ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Undefined reference to ros::init

asked 2016-12-10 21:41:27 -0500

Joy16 gravatar image

updated 2016-12-11 03:15:42 -0500

gvdhoorn gravatar image

Hi! When I am trying to catkin_make, I am getting this error:

CMakeFiles/parser.dir/src/parser.cpp.o: In function `main':
parser.cpp:(.text+0x7e): undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
parser.cpp:(.text+0xda): 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&)'
parser.cpp:(.text+0x1ac): undefined reference to `ros::spin()'
parser.cpp:(.text+0x1c0): undefined reference to `ros::Subscriber::~Subscriber()'
parser.cpp:(.text+0x1cf): undefined reference to `ros::NodeHandle::~NodeHandle()'
parser.cpp:(.text+0x22d): undefined reference to `ros::NodeHandle::~NodeHandle()'
parser.cpp:(.text+0x25e): undefined reference to `ros::NodeHandle::~NodeHandle()'
parser.cpp:(.text+0x28f): undefined reference to `ros::Subscriber::~Subscriber()'
parser.cpp:(.text+0x2c6): undefined reference to `ros::Subscriber::~Subscriber()'
parser.cpp:(.text+0x2da): undefined reference to `ros::Subscriber::~Subscriber()'
parser.cpp:(.text+0x2ee): undefined reference to `ros::NodeHandle::~NodeHandle()'

I am not sure why the error is coming from. My executable file name is parser.cpp

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(gmm)

find_package(catkin REQUIRED)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES gmm
#  CATKIN_DEPENDS other_catkin_pkg
#  DEPENDS system_lib
)

#############
## Testing ##
#############

include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(parser src/parser.cpp)
target_link_libraries(parser ${catkin_LIBRARIES})

This is my package.xml:

<?xml version="1.0"?>
<package>
  <name>gmm</name>
  <version>0.0.0</version>
  <description>The gmm package</description>


  <maintainer email="joy@todo.todo">joy</maintainer>
  <license>TODO</license>


  <buildtool_depend>catkin</buildtool_depend>

   <build_depend>std_msgs</build_depend>
   <build_depend>sensor_msgs</build_depend>
   <build_depend>roscpp</build_depend>  


   <run_depend>std_msgs</run_depend>
   <run_depend>sensor_msgs</run_depend>
   <run_depend>roscpp</run_depend>  
  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->

  </export>
</package>

Could you please help me out here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-12-11 00:47:03 -0500

You are declaring in your package manifest that your project depends on std_msgs, sensor_msgs and roscpp but you forgot to tell cmake about it.

In your CMakeLists.txt file replace the line:

find_package(catkin REQUIRED)

for:

find_package(catking REQUIRED COMPONENTS std_msgs sensor_msgs roscpp)

That way catkin can find the appropriate headers and libraries for your project.

edit flag offensive delete link more

Comments

@Joy16: perhaps CMakeLists.txt vs package.xml can shed some light on why you have to 'duplicate' this information in both.

gvdhoorn gravatar image gvdhoorn  ( 2016-12-11 03:17:23 -0500 )edit

Thanks! That worked.

Joy16 gravatar image Joy16  ( 2016-12-11 17:47:12 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-10 21:41:27 -0500

Seen: 1,512 times

Last updated: Dec 11 '16