ROS CMakeList.tx配置出错 add_dependencies位置出错

执行catkin_make时出错,错误如下:

CMake Error at test_code/CMakeLists.txt:135 (add_dependencies):
  Cannot add target-level dependencies to non-existent target "test_code".

  The add_dependencies works for top-level logical targets created by the
  add_executable, add_library, or add_custom_target commands.  If you want to
  add file-level dependencies see the DEPENDS option of the add_custom_target
  and add_custom_command commands.


-- Configuring incomplete, errors occurred!
See also "/home/lin/firtst_homework/build/CMakeFiles/CMakeOutput.log".
See also "/home/lin/firtst_homework/build/CMakeFiles/CMakeError.log".
Invoking "cmake" failed

错误的原因是,add_dependencies()的位置错了,注意CMakeList.txt文件中,add_exacutable()的上下文都存在add_dependencies(),需要在add_exacutable()的下方add_dependencies()。

错误原文件如下:

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(test_code ${catkin_EXPORTED_TARGETS})
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/test01_node.cpp)
add_executable(test_code src/test_code.cpp)
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
target_link_libraries(test_code
  ${catkin_LIBRARIES}
  ${EIGEN3_LIBRARIES}
  glog
  gflags
)

修改如下:

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/test01_node.cpp)
add_executable(test_code src/test_code.cpp)
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(test_code ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
target_link_libraries(test_code
  ${catkin_LIBRARIES}
  ${EIGEN3_LIBRARIES}
  glog
  gflags
)

主要还是没仔细看英文注释,其实注释写的很清楚了:

## Add cmake target dependencies of the library --> 添加库的依赖
## ...
add_executable(test_code src/test_code.cpp)
## Add cmake target dependencies of the executable --> 添加可执行文件的依赖
## ...
add_dependencies(test_code ${catkin_EXPORTED_TARGETS})

你可能感兴趣的:(opencv,机器人,人工智能)