在编译高博《自动驾驶与机器人中的SLAM技术》ch3时,出现报错:
../../../lib/libslam_in_auto_driving.tools.so: undefined reference to `tbb::interface7::internal::isolate_within_arena(tbb::interface7::internal::delegate_base&, long)'
collect2: error: ld returned 1 exit status
src/tools/CMakeFiles/ui_test.dir/build.make:833: recipe for target '../bin/ui_test' failed
make[2]: *** [../bin/ui_test] Error 1
CMakeFiles/Makefile2:3829: recipe for target 'src/tools/CMakeFiles/ui_test.dir/all' failed
make[1]: *** [src/tools/CMakeFiles/ui_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 94%] Built target slam_in_auto_driving.common
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2
前置条件:电脑已经将GCC升级到了9+版本
报错提示是未链接到tbb的库,当使用find_package(tbb)
或者find_package(TBB)
时,CMake提示无法找到这个库
解决办法:
在src/tools/CMakeLists.txt
中的两个target_link_libraries()
直接链接tbb的相关库文件:
/usr/local/lib/libtbb.so
/usr/local/lib/libtbbmalloc.so
/usr/local/lib/libtbbmalloc_proxy.so
完整的CMakeLists.txt如下:
add_library(${PROJECT_NAME}.tools
pointcloud_convert/velodyne_convertor.cc
pointcloud_convert/packets_parser.cc
ui/pangolin_window.cc
ui/pangolin_window_impl.cc
ui/ui_car.cc
ui/ui_trajectory.cc
ui/ui_cloud.cc
)
target_link_libraries(${PROJECT_NAME}.tools
# lusx add
/usr/local/lib/libtbb.so
/usr/local/lib/libtbbmalloc.so
/usr/local/lib/libtbbmalloc_proxy.so
${third_party_libs}
)
add_executable(ui_test ui/ui_test.cc)
target_link_libraries(ui_test
# lusx add
/usr/local/lib/libtbb.so
/usr/local/lib/libtbbmalloc.so
/usr/local/lib/libtbbmalloc_proxy.so
${PROJECT_NAME}.tools
${third_party_libs}
)