Ask Your Question

undefined reference to `ros::init (correct CMakeLists.txt)

asked 2016-09-26 15:51:04 -0500

bastianhjaeger gravatar image

updated 2016-09-27 00:05:30 -0500

Suddenly my caktin build does not work anymore.

Linking seem to fail. But the project works on other computers (all Ubuntu 16.04 and ROS kinetic).

I already tried:

  • setting up a new catkin ws
  • reinstalling ros completely
  • reinstall catkin
  • testing other nodes / packages

The linking error occurs in every package now. Maybe anyone can help.

Here is e.gcthe beginner_tutorials project: CMakeLists.txt:

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)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

# %EndTag(FULLTEXT)%


<?xml version="1.0"?>
<!-- %Tag(FULLTEXT,-1)% -->
  <!-- %Tag(NAME)% -->
  <!-- %EndTag(NAME)% -->
  <!-- %Tag(VERSION)% -->
  <!-- %EndTag(VERSION)% -->
  <!-- %Tag(DESC)% -->
  <description>The beginner_tutorials package</description>
  <!-- %EndTag(DESC)% -->

  <!-- %Tag(MAINTAINER)% -->
  <maintainer email="you@yourdomain.tld">Your Name</maintainer>
  <!-- %EndTag(MAINTAINER)% -->
  <!-- %Tag(LICENSE)% -->
  <!-- %EndTag(LICENSE)% -->
  <!-- %Tag(URLS)% -->
  <url type="website"></url>
  <!-- %EndTag(URLS)% -->
  <!-- %Tag(AUTHORS)% -->
  <author email="you@yourdomain.tld">Jane Doe</author>
  <!-- %EndTag(AUTHORS)% -->

  <!-- %Tag(DEPS)% -->


  <!-- %EndTag(DEPS)% -->

  <!-- %Tag(EXPORT)% -->
  <!-- %EndTag(EXPORT)% -->
<!-- %EndTag(FULLTEXT)% -->


#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>

int main(int argc, char **argv)
  ros::init(argc, argv, "talker");
  ros::NodeHandle n;

  ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);

  ros::Rate loop_rate(10);

  int count = 0;
  while (ros::ok())
    std_msgs::String msg;
    std::stringstream ss;
    ss << "hello world " << count; = ss.str();




  return 0;


jaeger@ubuntu:~/catkin-ws-2$ catkin build --verbose beginner_tutorials 
Profile:                     default
Extending:          [cached] /home/jaeger/catkin-ws/devel:/opt/ros/kinetic
Workspace:                   /home/jaeger/catkin-ws-2
Source Space:       [exists] /home/jaeger/catkin-ws-2/src
Log Space:          [exists] /home/jaeger/catkin-ws-2/logs
Build Space:        [exists] /home/jaeger/catkin-ws-2/build
Devel Space:        [exists] /home/jaeger/catkin-ws-2/devel
Install Space:      [unused] /home/jaeger/catkin-ws-2/install
DESTDIR:            [unused] None
Devel Space Layout:          linked
Install Space Layout:        None
Additional CMake Args:       None
Additional Make Args:        None
Additional catkin Make Args: None
Internal Make Job Server:    True
Cache Job Environments:      False
Whitelisted Packages:        None
Blacklisted Packages:        None
Workspace configuration appears valid.
[build] Found '15' packages in 0.0 seconds.                                                                                                                                                                 
[build] Package table is up to date.                                                                                                                                                                        
Starting  >>> beginner_tutorials                                                                                                                                                                            
Starting   >> beginner_tutorials:mkdir                                                                                                                                                                      
Starting   >> beginner_tutorials:mkdir                                                                                                                                                                      
Starting   >> beginner_tutorials:cache-manifest                                                                                                                                                             
Starting   >> beginner_tutorials:check                                                                                                                                                                      
Subprocess  > beginner_tutorials:check `cd /home/jaeger/catkin-ws-2/build/beginner_tutorials; catkin build --get-env beginner_tutorials | catkin env -si  /usr/bin/make cmake_check_build_system; cd -`     
Output     << beginner_tutorials:check /home/jaeger/catkin-ws-2/logs/beginner_tutorials/build.check.000.log                                                                                                 
/usr/bin/cmake -H/home/jaeger/catkin-ws-2/src/beginner_tutorials -B ...
edit retag flag offensive close merge delete


Have you put include ros in your code?

alienmon gravatar image alienmon  ( 2016-09-26 20:51:03 -0500 )edit

Yes, there is the normal include to ros/ros.h and it builds and runs on the other computer. In tht case there would anyway be an compiling not linking error, right.

bastianhjaeger gravatar image bastianhjaeger  ( 2016-09-26 23:06:51 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-09-27 01:58:03 -0500

ahendrix gravatar image

Have you changed your default compiler recently, or made C++11 mode the default? The ROS binaries are compiled with the older C++ library, and this makes them incompatible with code compiled with the C++11 libraries.

edit flag offensive delete link more


Yes, I recently updated to gcc 5.4.0 for some other program. But the 4.9.4 is still on my system. How can I tell catkin to use the old one? BUT: I jsut (ugly for my other settings) uninstalled gcc 5.4.0 and reinstalled 'sudo apt-get install --reinstall gcc-4.9' --> Not ros builds again. Thanks!!!

bastianhjaeger gravatar image bastianhjaeger  ( 2016-09-27 03:14:24 -0500 )edit

@miseryindevice: if you feel @ahendrix's answer answered your question, could you please mark the question as answered by ticking the checkmark to the left of it? Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2016-09-27 04:27:47 -0500 )edit

As to choosing a compiler for Catkin: look into the 'alternatives' tool on Ubuntu, or use the CXX and CC environment variables.

Note that this is not Catkin specific: when searching for documentation/hints, leave 'catkin' out of your queries.

gvdhoorn gravatar image gvdhoorn  ( 2016-09-27 04:28:51 -0500 )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: 2016-09-26 15:51:04 -0500

Seen: 427 times

Last updated: Sep 27 '16