catkin_make文件更新经验

先列出文件树
└── smartcar_description
├── CMakeLists.txt
├── config
│ ├── arm_controller_ur5.yaml
│ ├── joint_state_controller.yaml
│ └── myrviz.rviz
├── launch
│ ├── base.urdf.rviz.launch
│ ├── controller_utils.launch
│ └── scout_with_laser_gazebo.launch
├── meshes
│ ├── base_link.dae
│ ├── base_link_full.dae
│ ├── base_link.stl
│ ├── hokuyo.dae
│ ├── ur5
│ │ ├── collision
│ │ │ ├── base.stl
│ │ │ ├── forearm.stl
│ │ │ ├── shoulder.stl
│ │ │ ├── upperarm.stl
│ │ │ ├── wrist1.stl
│ │ │ ├── wrist2.stl
│ │ │ └── wrist3.stl
│ │ └── visual
│ │ ├── base.dae
│ │ ├── forearm.dae
│ │ ├── shoulder.dae
│ │ ├── upperarm.dae
│ │ ├── wrist1.dae
│ │ ├── wrist2.dae
│ │ └── wrist3.dae
│ ├── wheel_type1.dae
│ ├── wheel_type1.stl
│ ├── wheel_type2.dae
│ └── wheel_type2.stl
├── package.xml
├── pubjointstate.cpp
├── sendposition.py
├── urdf
│ ├── empty.urdf
│ ├── rplidar.xacro
│ ├── scout_v2.gazebo
│ ├── scout_v2.xacro
│ ├── scout_wheel.gazebo
│ ├── scout_wheel_type1.xacro
│ ├── scout_wheel_type2.xacro
│ ├── smartcar_with_rplidar.urdf
│ ├── smartcar_with_rplidar.xacro
│ ├── ur5_robot.urdf
│ ├── ur5.urdf.xacro
│ ├── ur.gazebo.xacro
│ ├── ur.transmission.xacro
│ └── useless.txt
└── worlds
├── cloister.world
├── playground.world
├── playpen.world
└── room.world
自己在调试ros通信的过程中写了一个消息发布的cpp文件,因为cmakelists文件中没有写关于c++和消息发布的东西,所以直接rosrun是不行的(这一点和Python写的文件,勾选可以作为可执行文件之后能直接用 完全不一样)。于是修改cmakelist文件。
一开始是按照古月的书中写的添加了三行

add_executable(pubjointstate src/pubjointstate.cpp)

add_dependencies(pubjointstate ${PROJECT_NAME}_generate_messages_cpp) 

target_link_libraries(pubjointstate ${catkin_LIBRARIES} )

但是编译报错。找不到cpp文件。一开始以为是路径没写全,于是改了“src/medical_robot/smartcar_description/pubjointstate.cpp”,但依然报错

Cannot find source file: src/medical_robot/smartcar_description/pubjointstate.cpp

思考了下,可能是这里的路径是跟cmakelist相对的,也就是说,以cmakelist所在的这一层为根,把往下的几层目录列出来即可。
可以从文件树中看出,我的pubjointstate.cpp是跟cmakelist在一层,所以直接写

add_executable(pubjointstate pubjointstate.cpp)

add_dependencies(pubjointstate ${PROJECT_NAME}_generate_messages_cpp) 

target_link_libraries(pubjointstate ${catkin_LIBRARIES} )

之后有报错

The dependency target "smartcar_description_generate_messages_cpp" of
  target "pubjointstate" does not exist.

于是对照古月的github文件中的cmakelists文件
发现少了下面这个部分

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  urdf
  xacro
  geometry_msgs
  roscpp
  rospy
  std_msgs
  message_generation
)

## Generate added messages and services with any dependencies listed here
generate_messages(
  DEPENDENCIES
  std_msgs  # Or other packages containing msgs
)

添加之后,编译通过了。。。。

里面有个警告:

 Invoking generate_messages() without having added any message or service
  file before.

  You should either add add_message_files() and/or add_service_files() calls
  or remove the invocation of generate_messages().
Call Stack (most recent call first):

虽然暂时没影响,但可以参考这个帖子。
https://blog.csdn.net/qq_16775293/article/details/80449203

你可能感兴趣的:(ros,经验分享)