glog 编译连接出错 undefined reference to _ux86_64_getcontext' 解决

209 阅读1分钟

glog 链接时出错,

stacktrace.cc:(.text+0x98): undefined reference to `_Ux86_64_getcontext'
/usr/bin/ld: stacktrace.cc:(.text+0xa3): undefined reference to `_ULx86_64_init_local'
/usr/bin/ld: stacktrace.cc:(.text+0xd1): undefined reference to `_ULx86_64_get_reg'
/usr/bin/ld: stacktrace.cc:(.text+0xe4): undefined reference to `_ULx86_64_step'
/usr/bin/ld: stacktrace.cc:(.text+0x127): undefined reference to `_ULx86_64_step'
collect2: error: ld returned 1 exit status

因为glog链接时需要 libunwind.so

查看是否已经安装了 libunwind.so
ldconfig -p | grep libunwind

如果没有安装,使用下面的命令安装:
sudo apt install libunwind-dev

解决办法: 修改CMakeList.txt

target_link_libraries 中增加 unwind

target_link_libraries(unwind)