Problem linking ros in ros::init

asked 2016-12-01 09:14:53 -0600

fcomuniz gravatar image

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

edit retag flag offensive close merge delete

Comments

I tried your code exactly and wasn't able to reproduce the error. Have you tried removing the build and devel directories and then do catkin_make again?

jsanch2s gravatar imagejsanch2s ( 2016-12-01 09:37:59 -0600 )edit

Yes, but it gives the same error again, i tried reinstalling ros-kinetic-desktop-full, but it gave the same error

fcomuniz gravatar imagefcomuniz ( 2016-12-01 10:19:41 -0600 )edit

Did you solve it? I have the same problem.

ipgvl gravatar imageipgvl ( 2019-02-04 02:36:10 -0600 )edit