Getting linker errors when linking against libunwind for a library in my project

∥☆過路亽.° 提交于 2021-02-10 18:14:03

问题


I am running this command --

/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

But I get this linker error --

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'

When I do nm -D I do see the symbols defined -

$ 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

Also, ldd of libXYZMaster.so indicates that the libunwind is linked --

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)

回答1:


For future reference, it is because I had not #defined UNW_LOCAL_ONLY before including ... Leaving it undefined lead to different function signature getting picked (at random perhaps).

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



来源:https://stackoverflow.com/questions/49438381/getting-linker-errors-when-linking-against-libunwind-for-a-library-in-my-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!