so库又一次遇到 undefined symbol------ldd, nm, c++filt命令大显身手
2017-08-01 23:10
543 查看
最近发版本, 灰度发布的时候, 发现进程没来, 回包自然是异常的。 立即进行版本回退, 发现OK.
哪里出问题了呢? 直接ldd -r libtest.so一下, 就知道了, 原来是缺符号。 看看简化后的示例代码:
#include <iostream>
using namespace std;
class Test
{
public:
void output();
};
#if 0
void Test::output()
{
cout << "output is celled" << endl;
}
#endif
void fun()
{
Test T;
T.output();
} 先编译成test.o, 然后编译成libtest.so, 不会有编译问题, 但如果其他模块来加载libtest.so, 就会有问题。 libtest.so为什么会有问题呢? 因为没有符号啊, 看看:
xxxxxx:~> ldd -r libtest.so
undefined symbol: _ZNSt8ios_base4InitC1Ev (./libtest.so)
undefined symbol: _ZNSt8ios_base4InitD1Ev (./libtest.so)
undefined symbol: _ZN4Test6outputEv (./libtest.so)
undefined symbol: __gxx_personality_v0 (./libtest.so)
linux-gate.so.1 => (0xbfffe000)
/lib/libonion.so (0xb7faa000)
libc.so.6 => /lib/libc.so.6 (0xb7e5f000)
libdl.so.2 => /lib/libdl.so.2 (0xb7e5a000)
/lib/ld-linux.so.2 (0x80000000)
xxxxxx:~> c++filt _ZN4Test6outputEv
Test::output()
xxxxxx:~> 一切一目了然。
再回忆一下, 之前我们遇到过类似问题, 最终发现是makefile中没有指定对应的静态库, 也就无法找到静态库中的函数。 其实, 这种情况和上述情况是完全一致的, 总之就是找不到函数的定义, 没有符号。
最后说一下, 如果你愿意, 用nm命令也可以哈, 如下:
xxxxxx:~> nm -u libtest.so
U __cxa_atexit@@GLIBC_2.1.3
w __cxa_finalize@@GLIBC_2.1.3
w __gmon_start__
U __gxx_personality_v0
w _Jv_RegisterClasses
U _ZN4Test6outputEv
U _ZNSt8ios_base4InitC1Ev
U _ZNSt8ios_base4InitD1Ev
xxxxxx:~> c++filt _ZN4Test6outputEv
Test::output()
xxxxxx:~>
不多说。
哪里出问题了呢? 直接ldd -r libtest.so一下, 就知道了, 原来是缺符号。 看看简化后的示例代码:
#include <iostream>
using namespace std;
class Test
{
public:
void output();
};
#if 0
void Test::output()
{
cout << "output is celled" << endl;
}
#endif
void fun()
{
Test T;
T.output();
} 先编译成test.o, 然后编译成libtest.so, 不会有编译问题, 但如果其他模块来加载libtest.so, 就会有问题。 libtest.so为什么会有问题呢? 因为没有符号啊, 看看:
xxxxxx:~> ldd -r libtest.so
undefined symbol: _ZNSt8ios_base4InitC1Ev (./libtest.so)
undefined symbol: _ZNSt8ios_base4InitD1Ev (./libtest.so)
undefined symbol: _ZN4Test6outputEv (./libtest.so)
undefined symbol: __gxx_personality_v0 (./libtest.so)
linux-gate.so.1 => (0xbfffe000)
/lib/libonion.so (0xb7faa000)
libc.so.6 => /lib/libc.so.6 (0xb7e5f000)
libdl.so.2 => /lib/libdl.so.2 (0xb7e5a000)
/lib/ld-linux.so.2 (0x80000000)
xxxxxx:~> c++filt _ZN4Test6outputEv
Test::output()
xxxxxx:~> 一切一目了然。
再回忆一下, 之前我们遇到过类似问题, 最终发现是makefile中没有指定对应的静态库, 也就无法找到静态库中的函数。 其实, 这种情况和上述情况是完全一致的, 总之就是找不到函数的定义, 没有符号。
最后说一下, 如果你愿意, 用nm命令也可以哈, 如下:
xxxxxx:~> nm -u libtest.so
U __cxa_atexit@@GLIBC_2.1.3
w __cxa_finalize@@GLIBC_2.1.3
w __gmon_start__
U __gxx_personality_v0
w _Jv_RegisterClasses
U _ZN4Test6outputEv
U _ZNSt8ios_base4InitC1Ev
U _ZNSt8ios_base4InitD1Ev
xxxxxx:~> c++filt _ZN4Test6outputEv
Test::output()
xxxxxx:~>
不多说。
相关文章推荐
- 用ldd -r, c++filt, nm搞定一个so库缺符号的问题
- ldd -r xxx.so命令的重要作用------见招拆招地解决缺库问题(undefined symbol)
- python 调用C++动态库所遇到的undefined symbol ***
- Linux下使用nm命令排查和解决“undefined reference to ”
- Linux下nm和ldd 命令
- Linux下编译C++程序遇到错误:undefined reference to '***'
- [Linux][2012-09-27] Linux nm && ldd 命令
- 相见恨晚:linux下的c++filt 命令
- Linux下eclipse编译C/C++程序遇到 undefined reference to `pthread_create'的异常解决办法
- Linux下nm和ldd 命令
- c++ 代码使用 dlopen/dlsym 时出现undefined symbol的问题
- C++ 动态加载库链接传入的类变量中的接口报undefined symbol问题
- nm 和 c++filt - [GNU/Linux]
- 编译C++程序遇到错误:undefined reference to `*::*
- 符号表,nm命令,EXPORT_SYMBOL 与 EXPORT_SYMBOL_GPL
- C++ 遇到error LNK2019: unresolved external symbol "public: void __thisca的问题
- Linux下nm和ldd 命令
- Linux C/C++ 开发遇到 undefined reference to xxx
- Linux调试、跟踪命令:strace/ltrace、ldd、objdump、nm、strings
- Linux下nm和ldd 命令