Ask Your Question
0

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

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

miseryindevice 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)
project(beginner_tutorials)

## 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

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)%

package.xml

<?xml version="1.0"?>
<!-- %Tag(FULLTEXT,-1)% -->
<package>
  <!-- %Tag(NAME)% -->
  <name>beginner_tutorials</name>
  <!-- %EndTag(NAME)% -->
  <!-- %Tag(VERSION)% -->
  <version>0.1.0</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)% -->
  <license>BSD</license>
  <!-- %EndTag(LICENSE)% -->
  <!-- %Tag(URLS)% -->
  <url type="website">http://wiki.ros.org/beginner_tutorials</url>
  <!-- %EndTag(URLS)% -->
  <!-- %Tag(AUTHORS)% -->
  <author email="you@yourdomain.tld">Jane Doe</author>
  <!-- %EndTag(AUTHORS)% -->

  <!-- %Tag(DEPS)% -->
  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>
  <!-- %EndTag(DEPS)% -->

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

talker.cpp

#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;
    msg.data = ss.str();

    ROS_INFO("%s", msg.data.c_str());

    chatter_pub.publish(msg);

    ros::spinOnce();
    loop_rate.sleep();
    ++count;
  }

  return 0;
}

Output

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 ...
(more)
edit retag flag offensive close merge delete

Comments

Have you put include ros in your code?

alienmon gravatar imagealienmon ( 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.

miseryindevice gravatar imagemiseryindevice ( 2016-09-26 23:06:51 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

Comments

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!!!

miseryindevice gravatar imagemiseryindevice ( 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 imagegvdhoorn ( 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 imagegvdhoorn ( 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

2 followers

Stats

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

Seen: 347 times

Last updated: Sep 27 '16