解決No rule to make target 'beginner_tutorials/CMakeFiles/talker.dir/build'。的一種可能性方法

問題現象:在構建項目時在命令行中出現

make[2]: *** No rule to make target 'beginner_tutorials/CMakeFiles/talker.dir/build'。 停止。
CMakeFiles/Makefile2:480: recipe for target 'beginner_tutorials/CMakeFiles/talker.dir/all' failed
make[1]: *** [beginner_tutorials/CMakeFiles/talker.dir/all] Error 2
make[1]: *** 正在等待未完成的任務....
make[2]: *** No rule to make target 'beginner_tutorials/CMakeFiles/listener.dir/build'。 停止。
CMakeFiles/Makefile2:443: recipe for target 'beginner_tutorials/CMakeFiles/listener.dir/all' failed
make[1]: *** [beginner_tutorials/CMakeFiles/listener.dir/all] Error 2
[100%] Built target beginner_tutorials_generate_messages
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

如下圖所示:



在wiki.ros.org上按步驟來的時候出錯http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

爲什麼呢?因爲在

修改CMakeList.txt時有一步驟不一定適合任何版本的ros

繼續使用我們上一節使用的自己創建的beginner_tutorial包。

此包的CMakeLists.txt文件應該如下所示(移除不必要的註釋之後):

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Declare ROS messages and services
add_message_files(DIRECTORY msg FILES Num.msg)
add_service_files(DIRECTORY srv FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

catkin_package()此行出錯,理論上應該版本低的ros修改成這樣可以編譯

實際上在前面我們創建ROS中的msg和srv文件中(http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv)


catkin_package(
  ...
  CATKIN_DEPENDS message_runtime ...
  ...)
這一步修改後的文件

爲catkin_package(CATKIN_DEPENDS roscpp rospy std_msgs message_runtime)

在早期版本中可以直接使用catkin_package()

將上面15行改成catkin_package(CATKIN_DEPENDS roscpp rospy std_msgs message_runtime)

關閉窗口退出即可。

然後在terminal中切換到相應的工作目錄

例如我的目錄爲~/dev/catkin_ws/

則在窗口中輸入

cd ~/dev/catkin_ws/

然後繼續輸入catkin_make

如果不出意外,應該會出現如下窗口

ok 成功!

發佈了45 篇原創文章 · 獲贊 26 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章