问题描述:
在colcon build时报错
/usr/bin/ld: /usr/local/lib/liblivox_sdk_static.a(device_discovery.cpp.o): relocation R_X86_64_TPOFF32 against symbol
_ZGVZN6spdlog7details2os9thread_idEvE3tid' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/local/lib/liblivox_sdk_static.a(livox_sdk.cpp.o): relocation R_X86_64_PC32 against symbol
stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: 最后的链结失败: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/livox_ros2_driver.dir/build.make:462:liblivox_ros2_driver.so] 错误 1问题描述:
make[1]: *** [CMakeFiles/Makefile2:80:CMakeFiles/livox_ros2_driver.dir/all] 错误 2
问题分析:
遇到报错不要慌,先仔细看日志,找到报错的原因
这个错误表明库文件liblivox_sdk_static.a
没有使用-fPIC
选项进行编译,而你正在尝试构建一个共享对象(shared object)。为了解决这个问题,你需要重新编译liblivox_sdk_static.a
库文件,并确保使用了-fPIC
选项。
问题解决:
SDK链接问题, 我们需要对SDK源码进行修改并重新编译安装SDK
在/livox-SDK/sdk_core/CMakeLists.cpp中找到如下行
set(SDK_LIBRARY ${PROJECT_NAME}_static)
add_library(${SDK_LIBRARY} STATIC "")
添加如下代码
target_compile_options(${SDK_LIBRARY} PRIVATE -fPIC)
使用target_compile_options()
函数来为${SDK_LIBRARY}
目标添加编译选项-fPIC
。这将确保在编译时为静态库设置了正确的位置无关代码(Position Independent Code)标志。
保存并关闭后重新编译livox-SDK
mkdir build && cd build
cmake ..
make -j4
sudo make install
然后在工作空间把之前编译生成的删除重新编译
colcon build
至此 问题解决。