天天看點

【ROS學習】catkin_make 編譯的小問題總結

寫在前面

本部落格旨在記錄一些自己在編譯 ROS 包的時候遇到的問題與解決方法

一、package.xml 下編譯依賴<build_depend> 标簽不全

執行 catkin_make 指令,出現如下報錯:

Traceback (most recent call last):
  File "/opt/ros/kinetic/share/genjava/cmake/../../../lib/genjava/genjava_gradle_project.py", line 14, in <module>
    genjava.main(sys.argv)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genjava/genjava_main.py", line 82, in main
    gradle_project.create(args.package, args.output_dir)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genjava/gradle_project.py", line 152, in create
    raise IOError("could not find %s among message packages. Does the package have a <build_depend> on message_generation in its package.xml?" % msg_pkg_name)
IOError: could not find lidar_localization among message packages. Does the package have a <build_depend> on message_generation in its package.xml?
lidar_localization/CMakeFiles/lidar_localization_generate_messages_java.dir/build.make:62: recipe for target 'lidar_localization/java/lidar_localization/build.gradle' failed
make[2]: *** [lidar_localization/java/lidar_localization/build.gradle] Error 1
CMakeFiles/Makefile2:3378: recipe for target 'lidar_localization/CMakeFiles/lidar_localization_generate_messages_java.dir/all' failed
make[1]: *** [lidar_localization/CMakeFiles/lidar_localization_generate_messages_java.dir/all] Error 2
[ 15%] Built target libGeographiccc
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

           
【ROS學習】catkin_make 編譯的小問題總結

注意報錯資訊裡面的這句話:

could not find %s among message packages. Does the package have a <build_depend> on message_generation in its package.xml
           

翻譯過來就是:

系統沒有找到一些package,你确定把他們都放到了 package.xml 中的 <build_depend>  标簽下了嗎?
           

是以需要確定 自己的 package.xml 中的 <build_depend> 标簽,有對應的 package (一般自定義的msg、srv、action,需要增加

<build_depend>message_generation</build_depend>

,這個容易忘記,自己就是忘記寫這句話,才編譯報錯的…)

二、xxxxxxxx.patch檔案找不到

執行 catkin_make 指令,出現如下報錯:

  1. glog_catkin檔案夾下的fix-unused-typedef-warning.patch檔案找不到
/bin/sh: 1: cannot open /home/wong/test_ws/src/fix-unused-typedef-warning.patch: No such file
misc/glog_catkin/CMakeFiles/glog_src.dir/build.make:101: recipe for target 'misc/glog_catkin/glog_src-prefix/src/glog_src-stamp/glog_src-patch' failed
make[2]: *** [misc/glog_catkin/glog_src-prefix/src/glog_src-stamp/glog_src-patch] Error 2
CMakeFiles/Makefile2:531: recipe for target 'misc/glog_catkin/CMakeFiles/glog_src.dir/all' failed
make[1]: *** [misc/glog_catkin/CMakeFiles/glog_src.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
           

原因是glog_catkin檔案夾下的fix-unused-typedef-warning.patch檔案找不到,修改CMakeLists.txt檔案:

解決方法:

(-) PATCH_COMMAND patch -p0 < ${CMAKE_SOURCE_DIR}/fix-unused-typedef-warning.patch
(+) PATCH_COMMAND patch -p0 < ${PROJECT_SOURCE_DIR}/fix-unused-typedef-warning.patch
           
  1. yaml_cpp_catkin 檔案夾下的 fextra_version.patch檔案找不到
/bin/sh: 1: cannot open /home/wong/test_ws/src/extra_version.patch: No such file
misc/yaml_cpp_catkin/CMakeFiles/yaml_cpp_src.dir/build.make:99: recipe for target 'misc/yaml_cpp_catkin/yaml_cpp_src-prefix/src/yaml_cpp_src-stamp/yaml_cpp_src-patch' failed
make[2]: *** [misc/yaml_cpp_catkin/yaml_cpp_src-prefix/src/yaml_cpp_src-stamp/yaml_cpp_src-patch] Error 2
CMakeFiles/Makefile2:6885: recipe for target 'misc/yaml_cpp_catkin/CMakeFiles/yaml_cpp_src.dir/all' failed
make[1]: *** [misc/yaml_cpp_catkin/CMakeFiles/yaml_cpp_src.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

           

原因是 yaml_cpp_catkin 檔案夾下的 fextra_version.patch檔案找不到,修改CMakeLists.txt檔案:

解決方法:

(-) PATCH_COMMAND patch -p0 < ${CMAKE_SOURCE_DIR}/fix-unused-typedef-warning.patch
(+) PATCH_COMMAND patch -p0 < ${PROJECT_SOURCE_DIR}/fix-unused-typedef-warning.patch
           

參考連結:https://github.com/MuMuJun97/learning_note/blob/master/markdown%20files/%E6%9C%AA%E5%88%86%E7%B1%BB/ETH%20github%20—%EF%BC%881%EF%BC%89kitti%E6%95%B0%E6%8D%AE%E9%9B%86%E7%82%B9%E4%BA%91ros%E8%BD%AC%E6%8D%A2%E6%A0%BC%E5%BC%8F.md

三、*** No rule to make target …

執行 catkin_make 指令,出現如下報錯:

make[2]: *** No rule to make target '/home/wong/test_ws/src/sim/rotors_simulator/rotors_gazebo_plugins/PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND', needed by 'sim/rotors_simulator/rotors_gazebo_plugins/MagneticField.pb.cc'.  Stop.
CMakeFiles/Makefile2:10218: recipe for target 'sim/rotors_simulator/rotors_gazebo_plugins/CMakeFiles/mav_msgs.dir/all' failed
make[1]: *** [sim/rotors_simulator/rotors_gazebo_plugins/CMakeFiles/mav_msgs.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
           

解決方法:

删除build檔案夾裡面的 rotors_gazebo_plugins ,然後重新 catkin_make 編譯

參考連結:

[1] ROS無人機仿真rotor_simulations配置篇 https://www.it610.com/article/1280133876655603712.htm

[2] makefile報錯 : make: No rule to make target https://blog.csdn.net/qq_27474467/article/details/80506882

四、Eigen庫 /usr/include/eigen3/Eigen/src/StlSupport/StdVector.h 報錯

執行 catkin_make 指令,出現如下報錯:

/usr/include/eigen3/Eigen/src/StlSupport/StdVector.h:72:9: error: partial specialization of ‘class std::vector<Type, Eigen::aligned_allocator<Type> >’ after instantiation of ‘class std::vector<std::queue<Eigen::Matrix<long int, 3, 1>, std::deque<Eigen::Matrix<long int, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<long int, 3, 1> > > >, Eigen::aligned_allocator<std::queue<Eigen::Matrix<long int, 3, 1>, std::deque<Eigen::Matrix<long int, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<long int, 3, 1> > > > > >’ [-fpermissive]
   class vector<T,EIGEN_ALIGNED_ALLOCATOR<T> >
           

解決方法:

在出現錯誤相關聯的檔案中添加

#include <Eigen/StdVector>

,問題就會消失。

我自己遇到的情況是:

終端列印報錯的檔案都是在 map_manager_voxblox_impl.h 檔案裡,是以我在這個檔案裡添加

#include <Eigen/StdVector>

就成功編譯了。

/home/wong/test_ws/src/exploration/mbplanner_ros/planner_common/include/planner_common/map_manager_voxblox_impl.h:97:10: error: ‘Index’ is not a member of ‘Eigen’
     for (Eigen::Index i = 0; i < matrix.size(); ++i) {
          ^
/home/wong/test_ws/src/exploration/mbplanner_ros/planner_common/include/planner_common/map_manager_voxblox_impl.h:97:30: error: ‘i’ was not declared in this scope
     for (Eigen::Index i = 0; i < matrix.size(); ++i) {

           

參考連結:

[1] ubuntu14.04安裝maplab及問題詳解 https://blog.csdn.net/snnily/article/details/79038726

[2] DSO_PCL踩坑+CMake+Boost+ROS+PCL+Eigen3 – https://www.jianshu.com/p/da9a859a9a8d

五、error: ‘Index’ is not a member of ‘Eigen’

執行 catkin_make 指令,出現如下報錯:

/home/wong/test_ws/src/exploration/mbplanner_ros/planner_common/include/planner_common/map_manager_voxblox_impl.h:99:10: error: ‘Index’ is not a member of ‘Eigen’
     for (Eigen::Index i = 0; i < matrix.size(); ++i) {
           

報錯顯示:Index 不是 Eigen 的成員。

(這個自己沒有查到,可能是Eigen版本的問題,自己看到 參考連結裡面有涉及到

Eigen::Index

Eigen::VectorXd::Index

,是以就直接改成了

Eigen::VectorXd::Index

考慮到自己程式裡這部分隻是一個 普通的數值類型的 i,是以把程式中的

Eigen::Index

直接換成

Eigen::VectorXd::Index

解決方法:

把程式中的

Eigen::Index

換成

Eigen::VectorXd::Index

,然後重新 catkin_make 編譯

參考連結:

[1] Use Eigen::Index instead of Eigen::VectorXd::Index :https://github.com/foobar27/anomaly/commit/7f62c152899eab808f57d8374379c4ea44f1c770