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

error when build catkin package

asked 2013-01-15 16:20:19 -0500

AdrianPeng gravatar image

updated 2013-01-16 04:37:22 -0500

I have already make a catkin work space following the ROS tutorial. And I also have created a catkin package in source folder. So next I tried to build the catkin package. Everything works before I add the c++ source file into the source folder of the catkin package. After I add the c++ source file, configuration step works fine. But next when I run "make" to build the package, this kind of error appears. It seems it cannot find ROS library.

CMakeFiles/joy_teleop_node.dir/src/joy_teleop_node.cpp.o: In function `TeleopTurtle::TeleopTurtle()':
joy_teleop_node.cpp:(.text+0x37): undefined reference to `ros::NodeHandle::NodeHandle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)'
joy_teleop_node.cpp:(.text+0x2a2): undefined reference to `ros::Publisher::~Publisher()'
joy_teleop_node.cpp:(.text+0x366): undefined reference to `ros::Subscriber::~Subscriber()'
joy_teleop_node.cpp:(.text+0x443): undefined reference to `ros::Publisher::~Publisher()'
joy_teleop_node.cpp:(.text+0x470): undefined reference to `ros::Subscriber::~Subscriber()'
joy_teleop_node.cpp:(.text+0x4ae): undefined reference to `ros::Subscriber::~Subscriber()'
joy_teleop_node.cpp:(.text+0x4c0): undefined reference to `ros::Publisher::~Publisher()'
joy_teleop_node.cpp:(.text+0x4cf): undefined reference to `ros::NodeHandle::~NodeHandle()'

This is package.xml:

<?xml version="1.0"?>
<description>The joy_teleop package</description>
<maintainer email="">adrian</maintainer>

And this is CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)
find_package(catkin REQUIRED COMPONENTS joy roscpp turtlesim)
add_executable(joy_teleop_node src/joy_teleop_node.cpp)

I can build the source file using rosbuild method, but not catkin.

Anyone can help me? Thanks in advance!

edit retag flag offensive close merge delete


Is this part of a tutorial? If so, can you tell us the URL of the tutorial so that someone can correct / add clarification to it?

130s gravatar image 130s  ( 2013-01-15 20:48:15 -0500 )edit

Yeah, I have added the link to my question.

AdrianPeng gravatar image AdrianPeng  ( 2013-01-16 04:38:18 -0500 )edit

Thanks. I modified wiki

130s gravatar image 130s  ( 2013-01-16 06:22:23 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-01-15 20:45:35 -0500

130s gravatar image

Since undefined reference indicates linker error in general in C and C++, you need to link your target to the appropriate libraries. Try adding the following to your CMakeLists.txt:

target_link_libraries(joy_teleop_node ${catkin_LIBRARIES})
edit flag offensive delete link more


Yeah! It works! Thank you very much!

AdrianPeng gravatar image AdrianPeng  ( 2013-01-16 04:33:39 -0500 )edit

Question Tools


Asked: 2013-01-15 16:20:19 -0500

Seen: 9,806 times

Last updated: Jan 16 '13