undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'

asked 2019-10-01 03:40:22 -0600

Dhananjay gravatar image

updated 2019-10-01 03:42:14 -0600

gvdhoorn gravatar image

I am trying to make darknet ros but i am getting above error. Complete log details below:

CMakeFiles/darknet_ros.dir/src/yolo_object_detector_node.cpp.o: In function `main':
/home/rde/ros_darknet/catkin_workspace/src/darknet_ros/darknet_ros/src/yolo_object_detector_node.cpp:13: undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
/home/rde/ros_darknet/catkin_workspace/src/darknet_ros/darknet_ros/src/yolo_object_detector_node.cpp:14: undefined reference to `ros::NodeHandle::NodeHandle(std::string const&, std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&)'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::getParam(std::string const&, double&) const'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::getParam(std::string const&, float&) const'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::hasParam(std::string const&) const'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `image_transport::ImageTransport::subscribe(std::string const&, unsigned int, boost::function<void (boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)> const&, boost::shared_ptr<void> const&, image_transport::TransportHints const&)'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::NodeHandle(ros::NodeHandle const&, std::string const&)'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `cv_bridge::toCvCopy(sensor_msgs::Image_<std::allocator<void> > const&, std::string const&)'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::getParam(std::string const&, std::vector<std::string, std::allocator<std::string> >&) const'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::searchParam(std::string const&, std::string&) const'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::getParam(std::string const&, bool&) const'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `cv_bridge::toCvCopy(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&, std::string const&)'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::getParam(std::string const&, std::string&) const'
/home/rde/ros_darknet/catkin_workspace/devel/lib/libdarknet_ros_lib.so: undefined reference to `ros::NodeHandle::getParam(std::string const&, int&) const'
collect2: error: ld returned 1 exit status
darknet_ros/darknet_ros/CMakeFiles/darknet_ros.dir/build.make:202: recipe for target '/home/rde/ros_darknet/catkin_workspace/devel/lib/darknet_ros/darknet_ros' failed
make[2]: *** [/home/rde/ros_darknet/catkin_workspace/devel/lib/darknet_ros/darknet_ros] Error 1
CMakeFiles/Makefile2:2022: recipe for target 'darknet_ros/darknet_ros/CMakeFiles/darknet_ros.dir/all' failed
make[1]: *** [darknet_ros/darknet_ros/CMakeFiles/darknet_ros.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

My CMakeList.txt file looks like :

cmake_minimum_required(VERSION 2.8.12)
project(darknet_ros)

# Set c++11 cmake flags
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-Wall -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-variable -Wfatal-errors -fPIC ${CMAKE_C_FLAGS}")

# Define path of darknet folder here.
find_path(DARKNET_PATH
  NAMES "README.md"
  HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../darknet/")
message(STATUS "Darknet path ...
(more)
edit retag flag offensive close merge delete

Comments

You probably didn't come here to get asked this, but: have you asked the darknet_ros package maintainers / authors? They would be the ones in a perfect position to help you, seeing as it's their package.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-01 03:43:18 -0600 )edit

Wouldn't you want to add ${catkin_LIBRARIES} to your executable in the CMakeLists?

target_link_libraries(${PROJECT_NAME}
  ${PROJECT_NAME}_lib
  ${catkin_LIBRARIES}
)
jschleicher@Pilz gravatar imagejschleicher@Pilz ( 2019-10-01 05:49:41 -0600 )edit

Not required.. Issue was due to the c compiler... I replace compiler to clang then it worked fine for me...

Dhananjay gravatar imageDhananjay ( 2019-10-11 03:47:04 -0600 )edit