undefined reference to `ros::init (correct CMakeLists.txt)
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 ...
Have you put include ros in your code?
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.