繁体   English   中英

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

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

我观察到,当我在Linux上编译程序时,目标文件中的某些符号未定义为“ U”(U表示已引用该函数,但未定义)。

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

程序仍然可以编译,没有任何链接器错误。 链接在这里如何发生? “ U”符号类型确切表示什么?

如果希望链接器检查未定义的符号并报告错误,则可以使用--no-undefined选项

我认为未使用这些符号,这就是链接器忽略h​​tem的原因。

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

参见“ man ld”

--unresolved-symbols =方法确定如何处理未解析的符号。 方法有四个可能的值:

       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