简体   繁体   English

目标文件中具有“ U”未定义符号类型的程序如何编译而没有任何链接程序错误?

[英]How does a program with “U” undefined symbol type in an object file, compiles without any linker errors?

I observe that when I compile a program (on linux), some of the symbols in object file are undefined "U" (U indicates the function is referenced, but not defined). 我观察到,当我在Linux上编译程序时,目标文件中的某些符号未定义为“ U”(U表示已引用该函数,但未定义)。

Example: 例:
XXX.cpp.o: XXX.cpp.o:
U _ZN5NJs16CRapidD2Ev U _ZN5NJs16CRapidD2Ev
U _ZN5NJs7CWriter6 U _ZN5NJs7CWriter6
U _ZN9NGeo22TConvertEi U _ZN9NGeo22TConvertEi

Still the program compiles without any linker error. 程序仍然可以编译,没有任何链接器错误。 How is the linking happening here? 链接在这里如何发生? What does "U" symbol type exactly signifies? “ U”符号类型确切表示什么?

If you want your linker to check undefined symbols and report an error you can use the option --no-undefined 如果希望链接器检查未定义的符号并报告错误,则可以使用--no-undefined选项

I think that these symbols are not used, that is why the linker ignores htem. 我认为未使用这些符号,这就是链接器忽略h​​tem的原因。

Linker option "-Wl,--unresolved-symbols=ignore-in-object-files" ignore undefined symbols in object files while creating executable 链接器选项“ -Wl,-unresolved-symbols = ignore-in-object-files”在创建可执行文件时忽略目标文件中的未定义符号

see "man ld" 参见“ man ld”

--unresolved-symbols=method Determine how to handle unresolved symbols. --unresolved-symbols =方法确定如何处理未解析的符号。 There are four possible values for method: 方法有四个可能的值:

       ignore-all
           Do not report any unresolved symbols.

       report-all
           Report all unresolved symbols.  This is the default.

       ignore-in-object-files
           Report unresolved symbols that are contained in shared libraries, but ignore them if they come from regular object files.

       ignore-in-shared-libs
           Report unresolved symbols that come from regular object files, but ignore them if they come from shared libraries.  This can be useful when
           creating a dynamic binary and it is known that all the shared libraries that it should be referencing are included on the linker's command line.

       The behaviour for shared libraries on their own can also be controlled by the --[no-]allow-shlib-undefined option.

       Normally the linker will generate an error message for each reported unresolved symbol but the option --warn-unresolved-symbols can change this to a
       warning.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM