Cannot specify link libraries for target “/opt/ros/noetic/lib/libroscpp.so“ which is not built by

catkin build的时候出现报错:

  Cannot specify link libraries for target "/opt/ros/noetic/lib/libroscpp.so"
  which is not built by this project.

发现原因是CMakeList.txttarget_link_libraries写反了。

原来将自定义的pub_data写在${catkin_LIBRARIES}的下方。

## Specify libraries to link a library or executable target against
target_link_libraries(
    ${catkin_LIBRARIES}
    pub_data
)

调整顺序,将自定义的pub_data写在${catkin_LIBRARIES}的上方,编译成功通过。

## Specify libraries to link a library or executable target against
target_link_libraries(
    pub_data
    ${catkin_LIBRARIES}
)

你可能感兴趣的:(ROS,c++,ubuntu)