Linking problem with ${catkin_LIBRARIES}
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
( http://wiki.ros.org/ROS/Tutorials/Wri... , 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)'
etc...
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)
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)
## 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
/opt/ros/kinetic/lib/libroscpp.so/usr/lib/x86_64-linux-gnu/libboost_filesystem.so/usr/lib/x86_64-linux-gnu/libboost_signals.so/opt/ros/kinetic/lib/librosconsole.so/opt/ros/kinetic/lib/librosconsole_log4cxx.so/opt/ros/kinetic/lib/librosconsole_backend_interface.so/usr/lib/x86_64-linux-gnu/liblog4cxx.so/usr/lib/x86_64-linux-gnu/libboost_regex.so/opt/ros/kinetic/lib/libxmlrpcpp.so/opt/ros/kinetic/lib/libroscpp_serialization.so/opt/ros/kinetic/lib/librostime.so/opt/ros/kinetic/lib/libcpp_common.so/usr/lib/x86_64-linux-gnu/libboost_system.so/usr/lib/x86_64-linux-gnu/libboost_thread.so/usr/lib/x86_64-linux-gnu/libboost_chrono.so/usr/lib/x86_64-linux-gnu/libboost_date_time.so/usr/lib/x86_64-linux-gnu/libboost_atomic.so/usr/lib/x86_64-linux-gnu/libpthread.so/usr/lib/x86_64-linux-gnu/libconsole_bridge.so
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: https://answers.ros.org/question/2062...
So if you have any ideas on that, let me know.
Thanks in advance!
EDIT 01: Added Code of listener.cpp and talker.cpp
listener.cpp
#include "ros/ros.h"
#include "std_msgs/String.h"
/**
* This tutorial demonstrates simple receipt of messages ...
please share the talker.cpp code. i guess, something wrong with cpp file
To be honest, I just copied the code from this tutorial: http://wiki.ros.org/ROS/Tutorials/Wri... (see EDIT 01) Moreover, I get the same error when I try to build other nodes, for example https://github.com/ros-drivers/velodyne