ch2:
问题:[ 50%] Building CXX object CMakeFiles/motion.dir/motion.cc.o
/home/u/slam_in_autonomous_driving-master/slam_in_autonomous_driving-master/src/ch2/motion.cc:8:10: fatal error: common/eigen_types.h: 没有那个文件或目录
8 | #include "common/eigen_types.h"
| ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/motion.dir/build.make:63:CMakeFiles/motion.dir/motion.cc.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:76:CMakeFiles/motion.dir/all] 错误 2
make: *** [Makefile:84:all] 错误 2
解决方案:
因为common的文件夹在ch2文件夹之外,因此在ch2中编译时读取不到common中的内容,后查阅资料,发现sadbook中的代码需要整体编译(即在slam_in_autonomous_driving-master文件夹中进行cmake编译)。
后续:
问题一:
make[2]: *** 没有规则可制作目标“gmock”,由“../bin/test_preintegration” 需求。 停止。 make[1]: *** [CMakeFiles/Makefile2:4171:src/ch4/CMakeFiles/test_preintegration.dir/all] 错误 2 make: *** [Makefile:141:all] 错误 2
解决方案:
其原因其实是gmock文件定位不准,解决方案如下,将/ch4/CmakeList.txt文件内容修改如下:
# 查找 Google Test,它应该也包含了 Google Mock
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# 添加您的库
add_library(${PROJECT_NAME}.ch4
gins_pre_integ.cc
imu_preintegration.cc
g2o_types.cc
)
# 添加您的测试可执行文件
add_executable(test_preintegration test_preintegration.cc)
# 链接 Google Test (它应该包含了 gmock) 以及其他依赖项
target_link_libraries(test_preintegration
${GTEST_BOTH_LIBRARIES}
pthread glog gflags ${PROJECT_NAME}.ch4 ${PROJECT_NAME}.ch3 ${PROJECT_NAME}.common
)
# 添加测试
add_test(NAME test_preintegration COMMAND test_preintegration)
# 添加其他可执行文件
add_executable(run_gins_pre_integ run_gins_pre_integ.cc)
target_link_libraries(run_gins_pre_integ
${PROJECT_NAME}.ch3
${PROJECT_NAME}.ch4
${G2O_LIBS}
)
问题2:make[2]: *** 没有规则可制作目标“gmock”,由“../bin/test_nn” 需求。 停止。 make[1]: *** [CMakeFiles/Makefile2:4227:src/ch5/CMakeFiles/test_nn.dir/all] 错误 2 make: *** [Makefile:141:all] 错误 2
解决方案:这个问题和上一个是一样的也是因为gmock的定位问题修改/ch5/CMakeList.txt内容为:
find_package(GTest REQUIRED)
add_executable(point_cloud_load_and_vis point_cloud_load_and_vis.cc)
target_link_libraries(point_cloud_load_and_vis
${PCL_LIBRARIES}
${GLOG_LIBRARIES}
gflags
)
add_executable(pcd_to_bird_eye pcd_to_bird_eye.cc)
target_link_libraries(pcd_to_bird_eye
${PCL_LIBRARIES}
${GLOG_LIBRARIES}
${OpenCV_LIBS}
gflags
)
add_executable(scan_to_range_image scan_to_range_image.cc)
target_link_libraries(scan_to_range_image
${PCL_LIBRARIES}
${GLOG_LIBRARIES}
${OpenCV_LIBS}
gflags
)
add_library(${PROJECT_NAME}.ch5
bfnn.cc
kdtree.cc
octo_tree.cc
)
target_link_libraries(${PROJECT_NAME}.ch5
tbb
)
add_executable(linear_fitting linear_fitting.cc)
target_link_libraries(linear_fitting
${PCL_LIBRARIES}
${GLOG_LIBRARIES}
${OpenCV_LIBS}
gflags
)
add_executable(test_nn test_nn.cc)
add_test(NAME test_nn COMMAND test_nn)
target_link_libraries(test_nn
GTest::GTest
GTest::Main
glog
gflags
${PROJECT_NAME}.ch5
${PROJECT_NAME}.common
${PCL_LIBRARIES}
tbb
)
最后编译成功,让我们一起欢呼GPT4万岁!感谢GPT4为我提供的解决方案
(持续更新)