ros2 / rosbag2_bag_v2

rosbag2 plugin for replaying ros1 version2 bag files
Apache License 2.0
25 stars 4 forks source link

Cannot link due to undefined class_loader symbols #32

Open KenYN opened 4 years ago

KenYN commented 4 years ago

I think this is a separate issue from #29 although it was initially reported under there. I get the following errors:

Starting >>> rosbag2_bag_v2_plugins
--- stderr: rosbag2_bag_v2_plugins                                
/opt/ros/noetic/lib/librviz.so: undefined reference to `class_loader::MultiLibraryClassLoader::getAllAvailableClassLoaders()'
/opt/ros/noetic/lib/librviz.so: undefined reference to `class_loader::impl::AbstractMetaObjectBase::isOwnedBy(class_loader::ClassLoader const*)'
/opt/ros/noetic/lib/librviz.so: undefined reference to `class_loader::MultiLibraryClassLoader::getRegisteredLibraries[abi:cxx11]()'
/opt/ros/noetic/lib/librviz.so: undefined reference to `class_loader::ClassLoader::isLibraryLoaded()'
/opt/ros/noetic/lib/librviz.so: undefined reference to `class_loader::systemLibrarySuffix[abi:cxx11]()'
collect2: error: ld returned 1 exit status
make[2]: *** [test_rosbag_v2_storage] Error 1
make[1]: *** [CMakeFiles/test_rosbag_v2_storage.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/test_rosbag_output_stream.dir/all] Error 2
make: *** [all] Error 2

Looking at the two libclass_loader.so I see this (and all other methods are const in foxy):

docker@PC:/opt/ros$ nm -C noetic/lib/libclass_loader.so  | grep "class_loader::systemLibrarySuffix"
000000000000ed00 T class_loader::systemLibrarySuffix[abi:cxx11]()
docker@PC:/opt/ros$ nm -C foxy/lib/libclass_loader.so  | grep "class_loader::systemLibrarySuffix"
docker@PC:/opt/ros$

So, the linker should be pulling in noetic/lib/libclass_loader.so but for some reason it is choosing the foxy version. I believe I am sourcing everything correctly:

source /opt/ros/noetic/setup.bash
source ../ros1/install/setup.bash
source ./install/setup.bash
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-up-to rosbag2_bag_v2_plugins --symlink-install

I'm not sure why librviz.so is being picked up - is this normal?

KenYN commented 4 years ago

OK, I've added a workaround similar to the nodelet one; in the CMakeLists.txt:

if((NOT "${ros1_message_package}" STREQUAL "nodelet") AND (NOT "${ros1_message_package}" STREQUAL "rviz"))

I still get the "Cannot generate a safe runtime search path for target rosbag2_bag_v2_plugins because there is a cycle in the constraint graph" warning, but otherwise it seems to be OK. ros2 bag info -s rosbag_v2 <path_to_bagfile> works as expected.

zygfrydw commented 4 years ago

Could you provide more details for your workaround? Which CMakeList.txt did you modify? Did you modify src/rosbag2_bag_v2/rosbag2_bag_v2_plugins/CMakeLists.txt? Did you wrap the entire file with

if((NOT "${ros1_message_package}" STREQUAL "nodelet") AND (NOT "${ros1_message_package}" STREQUAL "rviz"))

I am trying to build this plugin with eloquent and melodic and I get

CMake Warning at CMakeLists.txt:76 (add_library):
  Cannot generate a safe runtime search path for target
  rosbag2_bag_v2_plugins because there is a cycle in the constraint graph:

    dir 0 is [/home/zwieszok/projects/my_rosbag2/install/lib]
    dir 1 is [/opt/ros/eloquent/lib]
      dir 0 must precede it due to runtime library [libros1_rosbag_storage.so]
      dir 3 must precede it due to runtime library [libcv_bridge.so]
    dir 2 is [/opt/ros/eloquent/opt/yaml_cpp_vendor/lib]
    dir 3 is [/opt/ros/melodic/lib]
      dir 1 must precede it due to runtime library [libclass_loader.so]
    dir 4 is [/usr/lib/x86_64-linux-gnu/hdf5/openmpi]
    dir 5 is [/usr/lib/x86_64-linux-gnu/openmpi/lib]

  Some of these libraries may not be found correctly.

/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::impl::AbstractMetaObjectBase::isOwnedBy(class_loader::ClassLoader const*)'
/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::MultiLibraryClassLoader::getAllAvailableClassLoaders()'
/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::MultiLibraryClassLoader::getRegisteredLibraries[abi:cxx11]()'
/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::ClassLoader::isLibraryLoaded()'
collect2: error: ld returned 1 exit status
make[2]: *** [test_rosbag_output_stream] Error 1
make[1]: *** [CMakeFiles/test_rosbag_output_stream.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::impl::AbstractMetaObjectBase::isOwnedBy(class_loader::ClassLoader const*)'
/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::MultiLibraryClassLoader::getAllAvailableClassLoaders()'
/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::MultiLibraryClassLoader::getRegisteredLibraries[abi:cxx11]()'
/opt/ros/melodic/lib/librosbag_storage.so: undefined reference to `class_loader::ClassLoader::isLibraryLoaded()'
collect2: error: ld returned 1 exit status
make[2]: *** [test_rosbag_v2_storage] Error 1
make[1]: *** [CMakeFiles/test_rosbag_v2_storage.dir/all] Error 2
make: *** [all] Error 2
---
Failed   <<< rosbag2_bag_v2_plugins [50.1s, exited with code 2]
KenYN commented 4 years ago

I replaced this line with the indicated code. In your case, it seems to be rosbag_storage that is causing the problem, so it could be changed to this:

if((NOT "${ros1_message_package}" STREQUAL "nodelet") AND (NOT "${ros1_message_package}" STREQUAL "rosbag_storage")  
               AND (NOT "${ros1_message_package}" STREQUAL "rviz"))

Or perhaps it would be better and more compact as (not tested!):

set(ignore_packages nodelet rosbag_storage rviz)
if (NOT(${ros1_message_package} IN_LIST ignore_packages))
zygfrydw commented 4 years ago

It works! Thank you :+1: I still get the errors with graph cycles as you described, but it compiles nevertheless.

adithyab94 commented 1 year ago

What worked for me:

colcon build --packages-select rosbag2_bag_v2_plugins --cmake-args ' -Dclass_loader_INCLUDE_DIRS=/opt/ros/foxy/include/class_loader' '-Dclass_loader_LIBRARIES=/opt/ros/foxy/lib/libclass_loader.so'