ROS generate_messages_cpp [Compiler error resolution]

ROS generate_ messages_ Solution of CPP compilation error

Learning the knowledge of C + + and python joint programming under ROS, there is an error report when compiling cpp file, the following process is recorded:

    1. in the reference → Article 1 ← for configuration, the insertion of CPP and py has been completed, and

catkin is performed_ There are errors in the make

    1. steps, and the error contents are as follows:
CMake Error at my_pkg/CMakeLists.txt:27 (add_dependencies):
  The dependency target "my_pkg_generate_messages_cpp" of target "listener"
  does not exist.

The cmake version is adjusted according to Article 2 ←, and no error is reported. The principle is that cmake before 3.0 will turn this error report into a warning, and it has passed the compilation, but in actual use, it is still unable to find the listener program built from CPP. Finally, the cmakelists is adjusted according to Article 3 ←,
– first of all, Add the following code block:

catkin_package(
 INCLUDE_DIRS include
# LIBRARIES strands_gazing
 CATKIN_DEPENDS std_msgs
# DEPENDS system_lib
)

After that, in Add_ Added ${catkin> to dependencies _ EXPORTED_ Targets} finally, when compiling, execute catkin first_ make --pkg my_ PKG (here is the PKG name) , and then execute catkin_ Make problem solving

Finally, the revised cmakelists :

cmake_minimum_required(VERSION 3.0.2)
project(my_pkg)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

catkin_package(
  INCLUDE_DIRS include
# LIBRARIES strands_gazing
  CATKIN_DEPENDS std_msgs
# DEPENDS system_lib
)

include_directories(include/my_pkg ${catkin_INCLUDE_DIRS}) 
add_executable(listener src/listener.cpp) 
target_link_libraries(listener ${catkin_LIBRARIES}) 
add_dependencies(listener my_pkg_generate_messages_cpp ${catkin_EXPORTED_TARGETS})

Read More: