Ask Your Question

Linking problem with ${catkin_LIBRARIES}

asked 2018-05-22 12:57:43 -0600

FabianKu gravatar image

updated 2018-05-22 15:44:11 -0600

Hi everyone!

I'm currently trying to become familiar with ROS (I'm using Kinetic on Ubuntu 16.04 LTS) and followed the beginner tutorials. However, when I try to build the simple publisher/subscriber with catkin_make ( , Section 3.), I get the following error:

[ 64%] Built target beginner_tutorials_generate_messages_py
[ 70%] Linking CXX executable /home/fabian/catkin_ws/devel/lib/beginner_tutorials/talker
[ 82%] Built target beginner_tutorials_generate_messages_nodejs
[ 88%] Linking CXX executable /home/fabian/catkin_ws/devel/lib/beginner_tutorials/listener
[ 88%] Built target beginner_tutorials_generate_messages
CMakeFiles/talker.dir/src/talker.cpp.o: In function `main':
talker.cpp:(.text+0x70): undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
talker.cpp:(.text+0xcc): 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&)'
talker.cpp:(.text+0x29a): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'


So from my understanding (I did quite a lot of research in several discussion forums), this error actually appears, because the ROS libraries are not linked correctly to the executable. In my CMakeLists.txt I made sure that I added target_link_libraries(listener ${catkin_LIBRARIES}), the CMakeLists.txt looks as follows:

cmake_minimum_required(VERSION 2.8.3)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Declare ROS messages and services
add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
## Debug Message
message(STATUS "catkin_LIBRARIES: " ${catkin_LIBRARIES})
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)

add_executable(listener src/listener.cpp)
## Debug Message
message(STATUS "catkin_LIBRARIES: " ${catkin_LIBRARIES})
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

For debug purposes I added the message command to double-check the value of ${catkin_LIBRARIES}, it is


Since I'm pretty new to ROS and Ubuntu in general, I don't really know how to proceed. Seems like someone had a similar problem before, but never really solved it:

So if you have any ideas on that, let me know.

Thanks in advance!

EDIT 01: Added Code of listener.cpp and talker.cpp


#include "ros/ros.h"
#include "std_msgs/String.h"

 * This tutorial demonstrates simple receipt of messages ...
edit retag flag offensive close merge delete


please share the talker.cpp code. i guess, something wrong with cpp file

simbha gravatar image simbha  ( 2018-05-22 14:03:22 -0600 )edit

To be honest, I just copied the code from this tutorial: (see EDIT 01) Moreover, I get the same error when I try to build other nodes, for example

FabianKu gravatar image FabianKu  ( 2018-05-22 15:47:02 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted

answered 2018-05-22 22:08:44 -0600

ahendrix gravatar image

There seems to be something wrong with how you've set up your computer or how you've installed ROS.

In particular, it looks like all of the unresolved symbols involve std::string, which changed between gcc 4.9 and gcc 5.

The default compiler on 16.04 looks like it's gcc 5.3, and the ROS packages will be compiled with that version of gcc, but your ticket on the velodyne repo indicates that you've building with gcc 4.9. (This demonstrates the reverse problem: )

I am not sure that gcc 4.9 can build code that is compatible with the standard library that ships with gcc 5 and newer.

I strongly recommend that you use the default compiler that comes with your system.

edit flag offensive delete link more


@ahendrix Please, how do you use the default compiler?

ipgvl gravatar image ipgvl  ( 2019-02-04 03:41:53 -0600 )edit

The default compiler is the default; you shouldn't need to do anything special to use it, but if you've done anything to change the default compiler, you should undo that. There are so many different ways to override the default compiler, that I can't describe how to check for or undo all of them.

ahendrix gravatar image ahendrix  ( 2019-02-04 12:12:44 -0600 )edit

If you know that you have changed your default compiler and do not know how to restore it, perhaps consult a local linux expert, , or as a last resort reinstall Linux.

ahendrix gravatar image ahendrix  ( 2019-02-04 12:13:44 -0600 )edit

Thank you.

ipgvl gravatar image ipgvl  ( 2019-02-05 01:06:28 -0600 )edit

Note: this was fixed in #q314609 and/or #q313955.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-05 01:51:44 -0600 )edit

answered 2018-05-23 00:24:32 -0600

updated 2018-05-23 00:27:29 -0600

I guess this is the issue with the compiler. Just reinstall the gcc and g++. check the version of gcc -v 'g++ -v`.

I am using ros/indigo in ubuntu 14.04 and version of gcc and g++ are same 4.8.4.

Try to reinstall using sudo aptitude reinstall gcc g++

edit flag offensive delete link more

answered 2018-05-23 12:21:36 -0600

FabianKu gravatar image

Thanks a lot for your help guys! With the default gcc compiler (in my case 5.4.0) I was able to build the packages. There was actually no need to reinstall the compiler, I created an update alternative when I changed the compiler version for another project (as described here: ).

Sometimes solutions can be so simple.. Thanks again!

edit flag offensive delete link more

answered 2018-05-22 17:08:15 -0600

vinaykumarhs2020 gravatar image

Your CMakeLists.txt looks fine. Can you make sure you source /opt/ros/kinetic/setup.bash before you run catkin_make?

If that does not solve the problem, try running catkin_make clean or removing build directory in your workspace.

edit flag offensive delete link more


Thanks for the answer, but unfortunately it didn't help. I'm already sourcing /opt/ros/kinetic/setup.bash and /home/fabian/catkin_ws/devel/setup.bash in .bashrc. Also catkin_make clean doesn't make any difference. I also tried deleting and reinstalling the entire catkin workspace..

FabianKu gravatar image FabianKu  ( 2018-05-22 18:47:58 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-05-22 12:57:43 -0600

Seen: 2,777 times

Last updated: May 23 '18