mykl
mykl

Reputation: 5

loading rosbag duration using cpp

I am interested to load contents of rosbag into databse using sqlite and c++.

while including rosbag/view.h and rosbag/bag.h header file in my cpp file in visual studio code I am facing error of no such file or directory

code: ref http://wiki.ros.org/rosbag/Cookbook#C.2B-.2B-

#include <ros/ros.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>

int main(int argc, char **argv)
{
    rosbag::Bag bag;
    bag.open("input.bag", rosbag::bagmode::Read);
    
    rosbag::View view(bag);
   
    ros::Time bag_begin_time = view.getBeginTime();
    ros::Time bag_end_time = view.getEndTime();
  

        std::cout << "ROS bag time: " << (bag_end_time- 
     bag_begin_time).toSec() << "(s)" << std::endl;

    bag.close();
  
    return 0;
 }

error: main.cpp:2:10: fatal error: rosbag/bag.h: No such file or directory 2 | #include <rosbag/bag.h> | ^~~~~~~~~~~~~~

Upvotes: -3

Views: 645

Answers (1)

mykl
mykl

Reputation: 5

Issue is resolved by including ros package, directories and libraries in the CmakeLists.txt and executing the code with cmake and make respectively now able to see the rosbag duration.

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(esw2 VERSION 0.0.1 LANGUAGES CXX)

find_package(rosbag REQUIRED)

add_executable(folder_name
    file.cpp
)

target_include_directories(bag_reader
    PUBLIC
        include
        ${rosbag_INCLUDE_DIRS}
)

target_link_libraries(bag_reader
    PRIVATE
        ${rosbag_LIBRARIES}
        stdc++fs
)

Upvotes: 0

Related Questions