Problem linking ros in ros::init
I have a problem compiling the following code
// Include the ROS C++ APIs
#include <ros/ros.h>
// Standard C++ entry point
int main(int argc, char** argv) {
// Announce this program to the ROS master as a "node" called "hello_world_node"
ros::init(argc, argv, "hello_world_node");
// Start the node resource managers (communication, time, etc)
ros::start();
// Broadcast a simple log message
ROS_INFO("Hello, world!");
// Process ROS callbacks until receiving a SIGINT (ctrl-c)
ros::spin();
// Stop the node's resources
ros::shutdown();
// Exit tranquilly
return 0;
}
I'm using a ubuntu 16.04 with ros Kinetic, and use the follow CMakeLists.txt file
cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES beginner_tutorials
# CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
)
###########
## Build ##
###########
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(beginner_tutorials_node src/main.cpp)
#add_dependencies(beginner_tutorials_node ${catkin_EXPORTED_LIBRARIES})
target_link_libraries(beginner_tutorials_node
${catkin_LIBRARIES}
)
I get the following problem
CMakeFiles/beginner_tutorials_node.dir/src/main.cpp.o: In function `main':
main.cpp:(.text+0x55): undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
main.cpp:(.text+0xd2): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
collect2: error: ld returned 1 exit status
CMakeFiles/beginner_tutorials_node.dir/build.make:113: recipe for target 'devel/lib/beginner_tutorials/beginner_tutorials_node' failed
make[2]: *** [devel/lib/beginner_tutorials/beginner_tutorials_node] Error 1
CMakeFiles/Makefile2:707: recipe for target 'CMakeFiles/beginner_tutorials_node.dir/all' failed
make[1]: *** [CMakeFiles/beginner_tutorials_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
I tried many solutions, but none seemed to work
Asked by fcomuniz on 2016-12-01 10:14:53 UTC
Comments
I tried your code exactly and wasn't able to reproduce the error. Have you tried removing the
build
anddevel
directories and then docatkin_make
again?Asked by jsanch2s on 2016-12-01 10:37:59 UTC
Yes, but it gives the same error again, i tried reinstalling ros-kinetic-desktop-full, but it gave the same error
Asked by fcomuniz on 2016-12-01 11:19:41 UTC
Did you solve it? I have the same problem.
Asked by ipgvl on 2019-02-04 03:36:10 UTC