
The error you quote is basically a linking error, meaning the linker can't find the library that provides the binary code for a particular symbol you use.
This is not a ROS problem.
In this case you're not linking against the rosbag libraries.
You'll need to make sure that you've added rosbag to the find_package(catkin COMPONENTS ..) (or a regular find_package(..)) line in your CMakeLists.txt, and that you've added the appropriate target_link_libraries(..) that links your executable against the rosbag library.
As this is all CMake, you'll want to keep the CMake Documentation at hand.
Edit:
@gvdhoorn I made CMakeLists.txt as you suggested: like below:
cmake_minimum_required (VERSION 2.6)
project (tutorial)
find_package(catkin REQUIRED rosbag)
set(SOURCES sampleOne.cpp)
add_executable(test ${SOURCES})
target_link_libraries(test)
Two things here:
- if you just need
rosbag, there is no need for find_package(catkin ..), just use find_package(rosbag REQUIRED) directly.
- you have a
target_link_libraries(..) in there, but you don't actually link your test binary against any libraries.
The last point is actually why you're still getting errors.
both source code and CMakelists.txt is in a directory named "cmake_example".
Now I ran
cmake .
make
Please don't use in-source builds with CMake.
which does not product executable named "test"
but if I remove first line of source code
rosbag::Bag bag;
it does create executable named "test", which I can happily execute.
Which makes sense, as you're not actually linking against any of rosbag's libraries.
Try the following:
cmake_minimum_required(VERSION 2.6)
project (tutorial)
find_package(rosbag REQUIRED)
include_directories(${rosbag_INCLUDE_DIRS})
add_executable(test sampleOne.cpp)
target_link_libraries(test ${rosbag_LIBRARIES})
That will probably work.
Originally posted by gvdhoorn with karma: 86574 on 2017-07-07
This answer was ACCEPTED on the original site
Post score: 5
Original comments
Comment by Hridaynath on 2017-07-07:
@gvdhoorn
Thank you very much for your reply.
But I am trying to work with ROS Bag file in Isolation (that is no workspace, no package) usig CPP API.
I can read and manipulate data of Bag file in python without any workspace and package.
Comment by Hridaynath on 2017-07-07:
similarly for some task since there is no python library exist, I have to work in cpp.
So my next question is it impossible to work in isolation (that is without workspace and package)?
Comment by Hridaynath on 2017-07-07:
I have read some of website but I am clueless.
Comment by gvdhoorn on 2017-07-07:
I'm not sure what you are asking exactly. You don't need to have anything installed apart from the rosbag package, which can be build using just CMake. That should make both the C++ and the Python APIs available.
Comment by Hridaynath on 2017-07-10:
@gvdhoorn
I made CMakeLists.txt as you suggested: like below:
cmake_minimum_required (VERSION 2.6)
project (tutorial)
find_package(catkin REQUIRED rosbag)
set(SOURCES sampleOne.cpp)
add_executable(test ${SOURCES})
target_link_libraries(test)
Comment by Hridaynath on 2017-07-10:
I have following code in my "sampleOne.cpp" source file.
rosbag::Bag bag;
cout<<rosbag::bagmode::Read<<endl;
cout<<"hello done with ros bag instance"<<endl;
return 0;
Comment by Hridaynath on 2017-07-10:
both source code and CMakelists.txt is in a directory named "cmake_example".
Now I ran
cmake .
make
which does not product executable named "test"
but if I remove first line of source code
rosbag::Bag bag;
it does create executable named "test", which I can happily execute.
Comment by Hridaynath on 2017-07-10:
what I am missing.. I have almost trying for two days now. please help..
Comment by gvdhoorn on 2017-07-10:
I would suggest you append to your original question text next time, instead of using a nr of comments. Comments aren't suited for these kind of things.
Use the edit button/link to update your original question in that case.
Comment by Hridaynath on 2017-07-10:
@gvdhoorn
Thank you very much :)
The issue is solved and I could go ahead now.
(I learned something today.)
Use the edit button/link to update your original question in that case
Yes for sure I will keep this in mind next time.
Thank you very much :)