ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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)

find_package(catkin REQUIRED)

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

#  INCLUDE_DIRS include
#  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"?>
  <description>The gmm package</description>

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



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


Could you please help me out here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

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)


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


@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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 1,481 times

Last updated: Dec 11 '16