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

error when build catkin package

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

AdrianPeng gravatar image

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

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"?>
<package>
<name>joy_teleop</name>
<version>0.0.0</version>
<description>The joy_teleop package</description>
<maintainer email="quan1992@wpi.edu">adrian</maintainer>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>joy</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>turtlesim</build_depend>
<run_depend>joy</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>turtlesim</run_depend>
<export>
</export>
</package>

And this is CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)
project(joy_teleop)
find_package(catkin REQUIRED COMPONENTS joy roscpp turtlesim)
catkin_package(
INCLUDE_DIRS include
)
include_directories(include
${catkin_INCLUDE_DIRS}
)
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

Comments

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 -0600 )edit

Yeah, I have added the link to my question.

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

Thanks. I modified wiki

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

1 Answer

Sort by ยป oldest newest most voted
9

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

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

Comments

Yeah! It works! Thank you very much!

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

Question Tools

Stats

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

Seen: 9,858 times

Last updated: Jan 16 '13