一 遇到的问题:
catkin_make编译报错如下:
/usr/bin/ld: CMakeFiles/lio_sam_mapOptmization.dir/src/mapOptmization.cpp.o: undefined reference to symbol '_ZN3tbb8internal23allocate_via_handler_v3Em'
//usr/lib/x86_64-linux-gnu/libtbb.so.2: 无法添加符号: DSO missing from command line
collect2: error: ld returned 1 exit status
LIO-SAM/CMakeFiles/lio_sam_mapOptmization.dir/build.make:627: recipe for target '/home/sweetorange/catkin_lio/devel/lib/lio_sam/lio_sam_mapOptmization' failed
make[2]: *** [/home/sweetorange/catkin_lio/devel/lib/lio_sam/lio_sam_mapOptmization] Error 1
CMakeFiles/Makefile2:2479: recipe for target 'LIO-SAM/CMakeFiles/lio_sam_mapOptmization.dir/all' failed
make[1]: *** [LIO-SAM/CMakeFiles/lio_sam_mapOptmization.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j16 -l16" failed
二 问题原因:
未找到libtbb.so.2相关的库
三 解决办法:
使用
locate +库
完成库的搜索
如:我出问题的库为libtbb.so.2,在终端中使用命令locate即可获得该库所在位置:
locate libtbb.so.2
#我的结果↓:
/usr/lib/x86_64-linux-gnu/libtbb.so.2
一般化:把查到的结果加引号加到链接的库文件中去:
link_libraries("/usr/lib/x86_64-linux-gnu/libtbb.so.2")
我的修改后的代码:
#查询结果加引号加到gtsam后:
# Mapping Optimization
add_executable(${PROJECT_NAME}_mapOptmization src/mapOptmization.cpp)
add_dependencies(${PROJECT_NAME}_mapOptmization ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp)
target_compile_options(${PROJECT_NAME}_mapOptmization PRIVATE ${OpenMP_CXX_FLAGS})
target_link_libraries(${PROJECT_NAME}_mapOptmization ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenCV_LIBRARIES} ${OpenMP_CXX_FLAGS} gtsam "/usr/lib/x86_64-linux-gnu/libtbb.so.2")
# IMU Preintegration
add_executable(${PROJECT_NAME}_imuPreintegration src/imuPreintegration.cpp)
target_link_libraries(${PROJECT_NAME}_imuPreintegration ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenCV_LIBRARIES} gtsam "/usr/lib/x86_64-linux-gnu/libtbb.so.2")
至此我的代码就可以正常编译了.
举一反三:少其他库过程也是一样的.
版权声明:本文为sweetorange_原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。