Question for undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'

asked 2021-02-14 17:19:00 -0600

Xiaoxinxin gravatar image

updated 2021-02-15 11:46:54 -0600

gvdhoorn gravatar image

Straight dump of error:

undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
/usr/bin/ld: image_sub_pub.cpp:(.text+0xc7): undefined reference to `ros::spin()'
/usr/bin/ld: CMakeFiles/image_sub_pub_cpp.dir/src/image_sub_pub.cpp.o: in function `image_transport::TransportHints::TransportHints(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::TransportHints const&, ros::NodeHandle const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
image_sub_pub.cpp:(.text._ZN15image_transport14TransportHintsC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKN3ros14TransportHintsERKNS9_10NodeHandleES8_[_ZN15image_transport14TransportHintsC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKN3ros14TransportHintsERKNS9_10NodeHandleES8_]+0x57): undefined reference to `ros::NodeHandle::NodeHandle(ros::NodeHandle const&)'

From CMakefile

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  actionlib_msgs
  cv_bridge
  image_transport
  message_generation
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)

add_executable(image_sub_pub_cpp src/image_sub_pub.cpp)
target_link_libraries(image_sub_pub_cpp ${catkin_LIBRATIES})
target_link_libraries(image_sub_pub_cpp ${OpenCV_LIBRARIES})
edit retag flag offensive close merge delete

Comments

Hi, I do have ${OpenCV_INCLUDE_DIRS} under my include_directories, and target_link_libraries(image_sub_pub_cpp ${OpenCV_LIBRARIES})

Xiaoxinxin gravatar image Xiaoxinxin  ( 2021-02-15 14:12:38 -0600 )edit