简体   繁体   中英

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).

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

Still the program compiles without any linker error. How is the linking happening here? What does "U" symbol type exactly signifies?

If you want your linker to check undefined symbols and report an error you can use the option --no-undefined

I think that these symbols are not used, that is why the linker ignores htem.

Linker option "-Wl,--unresolved-symbols=ignore-in-object-files" ignore undefined symbols in object files while creating executable

see "man ld"

--unresolved-symbols=method Determine how to handle 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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