ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Undefined reference to ros::xx even after linking to ${catkin_LIBRARIES} [closed]

asked 2014-03-26 01:35:43 -0500

sotirios gravatar image

Hey everyone!

I'm pretty much used to ROS by now, but I got an error while catkin_make-ing a package that I can't really solve although it appears simple. I get all these errors while trying to link with the libraries:

CMakeFiles/data_input_output.dir/src/data_input_output.cpp.o: In function `main':
data_input_output.cpp:(.text+0x71): undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
data_input_output.cpp:(.text+0xc5): 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&)'
data_input_output.cpp:(.text+0x498): undefined reference to `ros::Rate::Rate(double)'
data_input_output.cpp:(.text+0x4ee): undefined reference to `ros::NodeHandle::getParam(std::string const&, int&) const'
data_input_output.cpp:(.text+0x54e): undefined reference to `ros::NodeHandle::getParam(std::string const&, double&) const'
data_input_output.cpp:(.text+0x56c): undefined reference to `ros::spinOnce()'
data_input_output.cpp:(.text+0x57a): undefined reference to `ros::Rate::sleep()'
data_input_output.cpp:(.text+0x586): undefined reference to `ros::ok()'
data_input_output.cpp:(.text+0x5af): undefined reference to `ros::Publisher::~Publisher()'
data_input_output.cpp:(.text+0x5bd): undefined reference to `ros::Publisher::~Publisher()'
data_input_output.cpp:(.text+0x5cb): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x5d9): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x5e7): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x5f5): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x600): undefined reference to `ros::NodeHandle::~NodeHandle()'
data_input_output.cpp:(.text+0x64c): undefined reference to `ros::NodeHandle::~NodeHandle()'
data_input_output.cpp:(.text+0x672): undefined reference to `ros::NodeHandle::~NodeHandle()'
data_input_output.cpp:(.text+0x69b): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x6cd): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x6f4): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x726): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x74d): undefined reference to `ros::Subscriber::~Subscriber()'
CMakeFiles/data_input_output.dir/src/data_input_output.cpp.o:data_input_output.cpp:(.text+0x77f): more undefined references to `ros::Subscriber::~Subscriber()' follow
CMakeFiles/data_input_output.dir/src/data_input_output.cpp.o: In function `main':
data_input_output.cpp:(.text+0x7ff): undefined reference to `ros::Publisher::~Publisher()'
data_input_output.cpp:(.text+0x835): undefined reference to `ros::Publisher::~Publisher()'
data_input_output.cpp:(.text+0x8aa): undefined reference to `ros::Publisher::~Publisher()'
data_input_output.cpp:(.text+0x8bc): undefined reference to `ros::Publisher::~Publisher()'
data_input_output.cpp:(.text+0x8ce): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x8e0): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x8f2): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x904): undefined reference to `ros::Subscriber::~Subscriber()'
data_input_output.cpp:(.text+0x913): undefined reference to `ros::NodeHandle::~NodeHandle()'

and some more... The problem appears to be with the linker that doesn't identify the catkin libraries. However, inside my CMakeLists/txt I have the following:

add_executable(data_input_output src/data_input_output.cpp)
target_link_libraries(data_input_output ${catkin_LIBRARIES})
add_dependencies(data_input_output localization_gencpp)

add_library(field_model src/field_model.cpp) # adding the field_model as a library
target_link_libraries(field_model ${catkin_LIBRARIES})
add_dependencies(field_model localization_gencpp)

add_executable(particle_filter_localization src/particle_filter_localization.cpp)
target_link_libraries(particle_filter_localization ${catkin_LIBRARIES})
target_link_libraries(particle_filter_localization ${gsl_LIBRARIES} ${GSLCBLAS_LIBRARY})
target_link_libraries(particle_filter_localization field_model) #link ...
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sotirios
close date 2014-03-26 15:51:13



I had the same error. For me, the problem was the following missing line in my CMakeList.txt:

target_link_libraries(your_node_name ${catkin_LIBRARIES})

It seems that the catkin_create_pkg command, under indigo, doesn't add this line automatically.

Luczia gravatar image Luczia  ( 2015-01-11 06:25:42 -0500 )edit

you need to add roscpp as required component, see accepted answer. If you want caktin_create_pkg to do this for you you must add roscpp as dependency (catkin_create_pkg your_package_name roscpp std_msgs <other dependencies>)

Wolf gravatar image Wolf  ( 2015-01-12 01:50:38 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-03-26 15:50:29 -0500

sotirios gravatar image

@ Wolf: I tried commenting the data_input_output target, but the rest still presented ros::xx undefined references, so it wasn't a problem of my target, just the linker altogether. I already had the roscpp included as a catkin required component, so I still couldn't understand what the root of the problem was.

However, after trying numerous things, I got to resolve my problem. I added the tf package as a catkin required component and I stopped getting those errors. I still don't know what the problem was and how the missing tf package led to undefined references to simple ros::xx functions, but it was resolved, so I'm going to close the thread. If you have any ideas about the reason, please share in the comments.

Thanks for your help anyway. :)

edit flag offensive delete link more


I'm facing the same issue. Funny thing is I have linked to catkin_LIBRARIES and I have roscpp, tf and visualization_msgs as catkin REQUIRES COMPONENTS. Still I'm getting undefined reference.

cybodroid gravatar image cybodroid  ( 2015-11-07 18:58:13 -0500 )edit

answered 2014-03-26 02:43:28 -0500

Wolf gravatar image

Do you have roscpp as catkin required component? 'find_package( catkin REQUIRED COMPONENTS roscpp )' Are you sure the others compile (changed order with other first or commented out data_input_output target) ?

edit flag offensive delete link more

Question Tools



Asked: 2014-03-26 01:35:43 -0500

Seen: 9,333 times

Last updated: Mar 26 '14