簡體   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