ROSbag c++ boost compiling problems
Hi folks,
Thanks for looking at my problem. I've been trying to write some code to convert .bags to csv files and have run into some problems. When I make the code, I get a large amount of errors when creating the .o. It's got to be in how I'm linking to the boost libraries...but I'm unskilled in this. My Cmake :
rosbuild_add_boost_directories()
rosbuild_add_executable(rosbag_to_csv src/make_csv.cpp)
rosbuild_link_boost(rosbag_to_csv system )
MY code:
#include <fstream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <ros/ros.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <boost/foreach.hpp>
#include <std_msgs/Int32.h>
//or just use $ rostopic echo -b file.bag -p /topic
int main(int argc, char *argv[])
{
if (argc > 1 || argc == 0)
{
std::cout << "Too many (or no) arguments........arg= filename.bag";
return -1;
}
std::cout << "Extracting data from: " << argv <<std::endl;
std::stringstream ss;
std::string argv_name;
std::string argv_fullname;
std::ofstream myfile;
time_t rawtime;
struct tm * timeinfo;
char str_now [80];
ss << argv;
ss >> argv_name;
argv_fullname=argv_name;
argv_name.erase(argv_name.end()-4,argv_name.end());
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (str_now,80,"%c",timeinfo);
myfile.open ((argv_name+ ".csv").c_str(), std::ios::out | std::ios::app);
myfile << str_now << "," << "ROSBAG decomposition: " << argv_name ;
rosbag::Bag bag;
bag.open(argv_fullname, rosbag::bagmode::Read);
rosbag::View view(bag);
BOOST_FOREACH(rosbag::MessageInstance const m, view)
{
if (m.getTopic() == "/cmd_vel/x")
{
std_msgs::Int32::ConstPtr value = m.instantiate<std_msgs::Int32>();
if (value != NULL)
{
myfile << value->data<< std::endl;
}
}//if topic
//else if (other topics) {}
}//boost
bag.close();
myfile.close();
return 0;
}//
Errors:
ew>':
/usr/include/boost/range/begin.hpp:49: undefined reference to rosbag::View::begin()'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
auto_any':
/usr/include/boost/foreach.hpp:250: undefined reference to rosbag::View::iterator::iterator(rosbag::View::iterator const&)'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
begin<rosbag::view, mpl_::bool_<false=""> >':
/usr/include/boost/foreach.hpp:650: undefined reference to rosbag::View::iterator::~iterator()'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
range_end<rosbag::view>':
/usr/include/boost/range/end.hpp:50: undefined reference to rosbag::View::end()'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
auto_any':
/usr/include/boost/foreach.hpp:250: undefined reference to rosbag::View::iterator::iterator(rosbag::View::iterator const&)'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
end<rosbag::view, mpl_::bool_<false=""> >':
/usr/include/boost/foreach.hpp:690: undefined reference to rosbag::View::iterator::~iterator()'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
increment<rosbag::view::iterator>':
/usr/include/boost/iterator/iterator_facade.hpp:523: undefined reference to rosbag::View::iterator::increment()'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
equal<rosbag::view::iterator, rosbag::view::iterator="">':
/usr/include/boost/iterator/iterator_facade.hpp:535: undefined reference to rosbag::View::iterator::equal(rosbag::View::iterator const&) const'
CMakeFiles/rosbag_to_csv.dir/src/make_csv.o: In function
dereference<rosbag::view::iterator>':
/usr/include/boost/iterator/iterator_facade.hpp:517: undefined reference to rosbag::View::iterator::dereference() const'
CMakeFiles/rosbag_to_csv.dir ...