error: ‘bag’ does not name a type
I have added rosbag dependencies in cmakefile.txt and package.xml and included essential ros headers but still catkin_make shows errors ( this not name a type that not name a type). Please help i really dont understand whats going wrong.
i have copied file from this ros tutorial : (http://wiki.ros.org/rosbag/Code%20API)
Make Error :
error: ‘bag’ does not name a type
bag.open("~/bagfiles/2016-12-20-18-18-30.bag", rosbag::bagmode::Read);
^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:11:1: error: ‘topics’ does not name a type
topics.push_back(std::string("chatter"));
^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:12:1: error: ‘topics’ does not name a type
topics.push_back(std::string("numbers"));
^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:16:2: error: expected unqualified-id before ‘if’
foreach(rosbag::MessageInstance const m, view)
^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:16:44: error: expected unqualified-id before ‘else’
foreach(rosbag::MessageInstance const m, view)
^
/home/mandeep/catkin_ws/src/proto1/proto1_moveit/src/rosplay.cpp:16:897: error: expected unqualified-id before ‘else’
foreach(rosbag::MessageInstance const m, view)
rosplay.cpp
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
rosbag::Bag bag;
bag.open("~/bagfiles/2016-12-20-18-18-30.bag", rosbag::bagmode::Read);
std::vector<std::string> topics;
topics.push_back(std::string("chatter"));
topics.push_back(std::string("numbers"));
rosbag::View view(bag, rosbag::TopicQuery(topics));
foreach(rosbag::MessageInstance const m, view)
{
std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
if (s != NULL)
ASSERT_EQ(s->data, std::string("foo"));
std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
if (i != NULL)
ASSERT_EQ(i->data, 42);
}
bag.close();
There goes my Cmakefiles.txt : Highlighted part added for rosplay.cpp
cmake_minimum_required(VERSION 2.8.3)
project(proto1_moveit)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake-modules) ####CHANGE
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) ####CHANGE
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) ####CHANGE
find_package(catkin REQUIRED COMPONENTS
moveit_core
moveit_ros_planning
moveit_ros_planning_interface
pluginlib
rosbag
cmake_modules
geometric_shapes
joint_trajectory_controller
joint_trajectory_action
moveit_simple_controller_manager
industrial_robot_simulator
actionlib
actionlib_msgs
control_msgs
trajectory_msgs
moveit_msgs
shape_msgs
chef_arm_kinematics
)
find_package(MySqlClient REQUIRED) ###CHANGE
find_package(Boost REQUIRED system filesystem date_time thread)
find_package(Eigen REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIR} ${EIGEN_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})
include_directories(${MYSQL_INCLUDE_DIRS}) ###CHANGE
catkin_package(
INCLUDE_DIRS
include
LIBRARIES
ik_utils_proto
pick_proto
place_proto
dispense_proto
stir_proto
CATKIN_DEPENDS
rosbag
moveit_core
moveit_ros_planning_interface
interactive_markers
std_msgs
actionlib_msgs
shape_msgs
chef_arm_kinematics
)
add_definitions(${MYSQL_DEFINITIONS}) ##CHANGE
add_library(pick_proto src/pick_proto.cpp)
target_link_libraries(pick_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS pick_proto
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_library(place_proto src/place_proto.cpp)
target_link_libraries(place_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS place_proto
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_library(dispense_proto src/dispense_proto.cpp)
target_link_libraries(dispense_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS dispense_proto
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_library(stir_proto src/stir_proto.cpp)
target_link_libraries(stir_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS stir_proto
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
add_executable(environment_proto src/environment_proto.cpp)
target_link_libraries(environment_proto ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${MYSQL_LIBRARIES}) ###CHANGE
install(TARGETS environment_proto DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
**add_executable(rosplay src/rosplay.cpp)
target_link_libraries(rosplay ${catkin_LIBRARIES} ${Boost_LIBRARIES})
install(TARGETS rosplay DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})**
install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
install ...
Please include your
CMakeLists.txt
andpackage.xml
and an example of the kind of errors you are getting.We cannot help you without the proper information.
I have added more info please help me.