C++ nm: "U" 符号未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2329722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nm: "U" The symbol is undefined
提问by bbazso
When I nm on one of my libs:
当我使用我的一个库时:
nm libmylib.so
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?
我检查了 nm 的手册页,我得到了“U”符号未定义。未定义符号的真正含义是什么?
If it is really undefined, then why does nm report it at all?
如果它真的是未定义的,那么 nm 为什么要报告它呢?
采纳答案by Troubadour
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.
在您的情况下,它看起来像您实现的 C 库中的一个符号,因此您希望它在您自己的库中未定义。它将在您的 libc.so 中定义,无论在哪里,可能是 /usr/lib。
回答by Fooo
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.
第二部分:“如果它未定义为什么报告”,, nm 实用程序将读取您的 lib 的整个符号表并打印它。因此,它只是读取和打印它而不对其进行任何操作。
回答by Carl Norum
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.
这意味着库引用了那个符号(std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage
在这种情况下?)但它没有定义它;你链接它的程序的某些部分,或者其他一些库应该这样做。如果您确实想在库中定义它,则意味着您没有将带有该符号定义的目标文件与库代码的其余部分链接起来。
回答by Carl Norum
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.
我认为它的意思是:在这个对象中未定义。一些符号在运行时被评估;这很可能就是其中之一。