1

我正在运行这个命令——

/usr/bin/c++ CMakeFiles/XYZ.dir/test/XYZ.cpp.o CMakeFiles/XYZ.dir/test/TempDir.cpp.o  
-o XYZ libXYZMaster.so -lboost_filesystem -lboost_system 
/usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so -lboost_random
-lboost_iostreams -lboost_thread -ldw -lunwind 
-Wl,-rpath,/home/user885/untitled/build

但我得到这个链接器错误——

libXYZMaster.so: undefined reference to `_Ux86_64_step'
libXYZMaster.so: undefined reference to `_Ux86_64_init_local'
libXYZMaster.so: undefined reference to `_Ux86_64_get_proc_name'
libXYZMaster.so: undefined reference to `_Ux86_64_get_reg'

当我做 nm -DI 确实看到定义的符号 -

$ nm -D /usr/lib/x86_64-linux-gnu/libunwind.so | grep -P "_step|init_local|get_proc_name|get_reg"
00000000000031d0 T _ULx86_64_get_proc_name
0000000000003370 T _ULx86_64_get_reg
0000000000004510 T _ULx86_64_init_local
0000000000004d20 T _ULx86_64_step

此外,libXYZMaster.so 的 ldd 表示 libunwind 已链接——

linux-vdso.so.1 =>  (0x00007ffd58f4a000)
libdw.so.1 => /usr/lib/x86_64-linux-gnu/libdw.so.1 (0x00007ff614bac000)
libunwind.so.8 => /usr/lib/x86_64-linux-gnu/libunwind.so.8 (0x00007ff614991000)
libboost_system.so.1.58.0 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0 (0x00007ff61478d000)
libboost_filesystem.so.1.58.0 => /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0 (0x00007ff614575000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff6141ec000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff613e22000)
libelf.so.1 => /usr/lib/x86_64-linux-gnu/libelf.so.1 (0x00007ff613c0a000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff613a06000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff6137ec000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007ff6135ca000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007ff6133ba000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff615084000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff61319d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff612f86000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff612c7d000)
4

1 回答 1

4

以供将来参考,这是因为我在包含...之前没有#defined UNW_LOCAL_ONLY 未定义导致选择不同的函数签名(也许是随机的)。

http://www.nongnu.org/libunwind/man/libunwind(3).html

于 2018-03-22T21:53:51.993 回答