nm symbol both "U" and "T", what does that mean?

时间:2018-11-16 21:38:08

标签: c++ undefined-symbol nm

I am having an undefined symbol error at runtime, and when I look for the symbol in the relevant library, I get the result:

nm -C -D /home/farmer/anaconda3/envs/general/lib/python3.6/site-packages/pyscannerbit/libScannerBitCAPI.so | grep empty_
                 U YAML::detail::node_data::empty_scalar[abi:cxx11]
00000000002b5860 T YAML::detail::node_data::empty_scalar[abi:cxx11]()

But how is that possible? The symbol is both undefined, and also in the library? What? Or are these actually different symbols? When mangled the names are indeed slightly different:

nm -D /home/farmer/anaconda3/envs/general/lib/python3.6/site-packages/pyscannerbit/libScannerBitCAPI.so | grep empty_
                 U _ZN4YAML6detail9node_data12empty_scalarB5cxx11E
00000000002b5860 T _ZN4YAML6detail9node_data12empty_scalarB5cxx11Ev

Does this make sense?

2 个答案:

答案 0 :(得分:1)

yaml-cpp有两种变体:

https://github.com/jbeder/yaml-cpp

https://github.com/jbeder/yaml-cpp.new-api

在第一个符号中,相关符号声明为成员static const std::string& empty_scalar();。 在第二个实例中,它被声明为成员static std::string empty_scalar;

您看到的两个符号名称与这两个不同的声明匹配。如果编译器看到empty_scalar这样声明不一致,则不应允许这样做。

我认为您链接了用不同版本的声明该符号的头文件编译的目标文件。链接器然后会因为这两个符号的名称不同而认为这两个符号不同。您使用的目标文件确实包含old-api变体的定义,但是一些代码正在使用新的。

答案 1 :(得分:0)

字母定义:

“ U”表示未定义符号。

“ T”表示该符号已在代码的“文本”部分中找到。

如果您看到grep搜索同时提出了这两种情况,则意味着这些符号中只有一个具有nm可以解析的定义。

相关问题