nm: "U" The symbol is undefined

C++LinkerDevelopment Environment

C++ Problem Overview


When I nm on one of my libs:

nm libmylib.so

I get a line like this

             U _ZNSs4_Rep20_S_empty_rep_storageE@@GLIBCXX_3.4

I checked the man page for nm and I got "U" The symbol is undefined. What does an undefined symbol really mean?

If it is really undefined, then why does nm report it at all?

C++ Solutions


Solution 1 - C++

An undefined symbol is a symbol that the library uses but was not defined in any of the object files that went into creating the library.

Usually the symbol is defined in another library which also needs to be linked in to your application. Alternatively the symbol is undefined because you've forgotten to build the code that defines the symbol or you've forgotten to include the object file with that symbol into your library.

In your case it looks like a symbol from your implementation's C library so you would expect that to be undefined in your own library. It will be defined in your libc.so wherever that is, possibly /usr/lib.

Solution 2 - C++

Deciphering this could be done like this :

           U _ZNSs4_Rep20_S_empty_rep_storageE@@GLIBCXX_3.4

Means:

    U->>> in your library its undefined

what is undefined ?

     _ZNSs4_Rep20_S_empty_rep_storageE

Where it is likely to find it ?

      GLIBCXX_3.4

Now for your question : " Why is it undefined : ", Its because The linker is not able to find its definition

Second Part : "If its undefined why report at all ", , nm utility shall read the whole symbol table of your lib and print it. So, its just reading & printing it without applying any operations on it.

Solution 3 - C++

It means that library references that symbol (std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage in this case?) but that it doesn't define it; some part of the program you link it with, or some other library is supposed to do that. If you did mean to define it in your library, it means you didn't link the object file with that symbol's definition with the rest of the library code.

Solution 4 - C++

I think it means exactly that: undefined in this object. Some symbols are evaluated at run time; this is likely to be one of them.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbbazsoView Question on Stackoverflow
Solution 1 - C++TroubadourView Answer on Stackoverflow
Solution 2 - C++AnotherDeveloperView Answer on Stackoverflow
Solution 3 - C++Carl NorumView Answer on Stackoverflow
Solution 4 - C++user257111View Answer on Stackoverflow