问题描述:
用catking_make在编译代码时候遇到以下错误:
(base) xdh@Pc:~/SLAM/std_ws$ catkin_make
Base path: /home/xdh/SLAM/std_ws
Source space: /home/xdh/SLAM/std_ws/src
Build space: /home/xdh/SLAM/std_ws/build
Devel space: /home/xdh/SLAM/std_ws/devel
Install space: /home/xdh/SLAM/std_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/xdh/SLAM/std_ws/build"
####
####
#### Running command: "make -j8 -l8" in "/home/xdh/SLAM/std_ws/build"
####
Scanning dependencies of target mytest
[ 20%] Built target pgo_demo
[ 40%] Built target online_demo
[ 60%] Built target place_recognition_livox
[ 80%] Built target place_recognition_kitti
[ 86%] Building CXX object STD/CMakeFiles/mytest.dir/demo/my_test.cpp.o
/home/xdh/SLAM/std_ws/src/STD/demo/my_test.cpp: In function ‘int main(int, char**)’:
/home/xdh/SLAM/std_ws/src/STD/demo/my_test.cpp:120:42: error: ‘t_descript’ was not declared in this scope; did you mean ‘t_descriptor_end’?
120 | descriptor_time.push_back(time_inc(t_descript n or_end, t_descriptor_begin));
| ^~~~~~~~~~
| t_descriptor_end
make[2]: *** [STD/CMakeFiles/mytest.dir/build.make:63:STD/CMakeFiles/mytest.dir/demo/my_test.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:570:STD/CMakeFiles/mytest.dir/all] 错误 2
make: *** [Makefile:141:all] 错误 2
Invoking "make -j8 -l8" failed
(base) xdh@Pc:~/SLAM/std_ws$ catkin_make
Base path: /home/xdh/SLAM/std_ws
Source space: /home/xdh/SLAM/std_ws/src
Build space: /home/xdh/SLAM/std_ws/build
Devel space: /home/xdh/SLAM/std_ws/devel
Install space: /home/xdh/SLAM/std_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/xdh/SLAM/std_ws/build"
####
####
#### Running command: "make -j8 -l8" in "/home/xdh/SLAM/std_ws/build"
####
Scanning dependencies of target mytest
[ 20%] Built target online_demo
[ 40%] Built target place_recognition_livox
[ 60%] Built target pgo_demo
[ 80%] Built target place_recognition_kitti
[ 86%] Building CXX object STD/CMakeFiles/mytest.dir/demo/my_test.cpp.o
[ 93%] Linking CXX executable /home/xdh/SLAM/std_ws/devel/lib/std_detector/mytest
/usr/bin/ld: CMakeFiles/mytest.dir/demo/my_test.cpp.o: in function `main':
my_test.cpp:(.text.startup+0x1508): undefined reference to `SCManager::makeAndSaveRinghashAndKeys(pcl::PointCloud<pcl::PointXYZI>&)'
collect2: error: ld returned 1 exit status
make[2]: *** [STD/CMakeFiles/mytest.dir/build.make:523:/home/xdh/SLAM/std_ws/devel/lib/std_detector/mytest] 错误 1
make[1]: *** [CMakeFiles/Makefile2:570:STD/CMakeFiles/mytest.dir/all] 错误 2
make: *** [Makefile:141:all] 错误 2
Invoking "make -j8 -l8" failed
后经过上网查找,发现这一般都是连接错误,错误的问题是编译器没有找到需要的代码文件,一般就是cmakelists.txt文件中的错误
解决方法:
修改之前和之后的代码:
add_executable(mytest demo/my_test.cpp src/STDesc.cpp)
target_link_libraries(mytest
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES})
add_executable(mytest demo/my_test.cpp src/STDesc.cpp demo/Scancontext.cpp)
target_link_libraries(mytest
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES})