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

Cannot include rosbag as catkin dependency

asked 2015-02-17 15:24:33 -0500

kamek gravatar image

I am having trouble including rosbag as a catkin dependency for my package (to use the C++ API). I have added it as both a build and run dependency in package.xml; i.e.,

<build_depend>rosbag</build_depend>
<run_depend>rosbag</build_depend>

And it is included in the correct places in CMakeLists.txt; i.e.,

find_package(catkin REQUIRED COMPONENTS
   pcl_ros
   roscpp
   rosbag
   sensor_msgs
)

and

catkin_package(
  INCLUDE_DIRS include
  CATKIN_DEPENDS pcl_ros roscpp sensor_msgs rosbag
)

Yet when I write the simple file

#include <ros/ros.h>
#include <rosbag/bag.h>
#include <string>
#include <iostream>

int main()
{
  rosbag::Bag bag;
  bag.open("test.bag", rosbag::bagmode::Read);

  std::vector<std::string> topics;
  topics.push_back(std::string("chatter"));
  topics.push_back(std::string("numbers"));

  bag.close();
}

I get the following when I invoke catkin_make:

CMakeFiles/write_json.dir/src/write_json.cpp.o: In function `main':
write_json.cpp:(.text.startup+0xe): undefined reference to `rosbag::Bag::Bag()'
write_json.cpp:(.text.startup+0x32): undefined reference to `rosbag::Bag::open(std::string const&, unsigned int)'
write_json.cpp:(.text.startup+0xd1): undefined reference to `rosbag::Bag::close()'
write_json.cpp:(.text.startup+0xe5): undefined reference to `rosbag::Bag::~Bag()'
write_json.cpp:(.text.startup+0xfd): undefined reference to `rosbag::Bag::~Bag()'
collect2: error: ld returned 1 exit status

Does anyone have any idea what I'm doing wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2015-02-17 16:37:38 -0500

William gravatar image

Those are linking errors, you need to link your library or executable (which contains write_json.cpp) against the rosbag libraries:

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

Question Tools

1 follower

Stats

Asked: 2015-02-17 15:24:33 -0500

Seen: 1,268 times

Last updated: Feb 17 '15