目标文件中带有 "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
我认为没有使用这些符号,这就是链接器忽略 htem 的原因。
链接器选项“-Wl,--unresolved-symbols=ignore-in-object-files”在创建可执行文件时忽略目标文件中未定义的符号
见"man ld"
--未解析的符号=方法
确定如何处理未解析的符号。 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.
我观察到当我编译程序时(在linux),目标文件中的一些符号是未定义的"U"(U 表示函数被引用,但未定义)。
示例:
XXX.cpp.o:
U _ZN5NJs16CRapidD2Ev
U _ZN5NJs7CWriter6
U _ZN9NGeo22TConvertEi
程序仍然可以编译,没有任何链接器错误。这里的链接是如何发生的? "U" 符号类型究竟表示什么?
如果您希望您的链接器检查未定义的符号并报告错误,您可以使用选项 --no-undefined
我认为没有使用这些符号,这就是链接器忽略 htem 的原因。
链接器选项“-Wl,--unresolved-symbols=ignore-in-object-files”在创建可执行文件时忽略目标文件中未定义的符号
见"man ld"
--未解析的符号=方法 确定如何处理未解析的符号。 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.