ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

ROS Noetic Issue with linking with LibTorch and class_loader

asked 2021-08-20 13:50:16 -0500

BenQ1110 gravatar image

updated 2021-08-21 19:16:40 -0500

Hi, I created a simple nodelet which was functioning correctly in ROS Melodic. However, when I moved to ROS Noetic I have encountered the following issue when running a launch file:

 /opt/ros/noetic/lib/nodelet/nodelet: symbol lookup error: /home/benksy/catkin_ws/devel/lib/libnodelet_plugins.so: undefined symbol: _ZN12class_loader4impl30getCurrentlyLoadingLibraryNameEv".

It corresponds to class_loader::impl::getCurrentlyLoadingLibraryName().

I attempted solutions from here https://answers.ros.org/question/2919... but with no success.

I presume there is a quick solution but I am not that familiar with CMake/C++ so any help appreciated.

Update 1:

I have noticed that the error pops up when I try to link Torch/LibTorch library to my nodelet. When target_link_libraries does not include ${TORCH_LIBRARIES}, the error does not show up.

Here is an example of CMakeLists.txt file:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(random_pkg)

list(APPEND CMAKE_PREFIX_PATH "/home/benksy/libtorch")

find_package(catkin REQUIRED COMPONENTS
  nodelet
  roscpp
  rospy
  roslib
 )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

## Setup include directories
include_directories(${catkin_INCLUDE_DIRS})


catkin_package(
#  INCLUDE_DIRS include
#   LIBRARIES nodelet_test_plugins
#   CATKIN_DEPENDS
#    lidar_msgs
#    roscpp
#    rospy
#    std_msgs
#  DEPENDS system_lib
)

## Create the nodelet tutorial library
add_library(nodelet_test_plugins
            src/test.cpp
            src/test.h
           )

find_package(Torch REQUIRED)
target_link_libraries(nodelet_test_plugins ${catkin_LIBRARIES} ${PROJECT_LIBRARIES} ${TORCH_LIBRARIES})

if(catkin_EXPORTED_LIBRARIES)
  add_dependencies(nodelet_test_plugins ${catkin_EXPORTED_LIBRARIES})
endif()

## Mark the nodelet library for installations
install(TARGETS nodelet_test_plugins
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

install(FILES nodelet_test_plugins.xml mynodelet.launch
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

All other files are empty/dummy.

test.cpp:

#include <pluginlib/class_list_macros.h>
#include "test.h"

PLUGINLIB_EXPORT_CLASS(random_pkg::Test, nodelet::Nodelet)

namespace random_pkg
{
  void Test::onInit()
  {}
}

test.h

#include "ros/ros.h"
#include <nodelet/nodelet.h>

namespace random_pkg
{
  class Test : public nodelet::Nodelet
  {
    public:
      Test(){}
    private:
      virtual void onInit();
    };
}

nodelet_test_plugins.xml

<library path="libnodelet_test_plugins">
  <class name="random_pkg/Test" type="random_pkg::Test" base_class_type="nodelet::Nodelet">
    <description>
      Write things here.
    </description>
  </class>

</library>

random.launch (When this file is launched the above error shows up)

<launch>

  <node pkg="nodelet" type="nodelet" name="standalone_nodelet"  args="manager" output="screen"/>

  <node pkg="nodelet" type="nodelet" name="Test" args="load random_pkg/Test standalone_nodelet" output="screen">
  </node>

</launch>

Other info: ROS Noetic/Ubuntu 20.04, gcc 9.3.0, LibTorch 1.9.0 (tried both CPU and GPU Cuda 11.1)

Thanks!

edit retag flag offensive close merge delete

Comments

Please provide enough information to reproduce your problem otherwise it's very hard to help you.

tfoote gravatar image tfoote  ( 2021-08-20 14:32:40 -0500 )edit

I updated the post. Thanks for help!

BenQ1110 gravatar image BenQ1110  ( 2021-08-20 16:00:50 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-20 17:46:32 -0500

BenQ1110 gravatar image

updated 2021-08-21 19:17:15 -0500

I have found a solution, and it is directly torch related.

When using gcc>=5.1 (as in Ubuntu 20.4/ROS Noetic), you have to use a cxx11 ABI version of the LibTorch package. Otherwise, you cannot link the libraries.

It is explained here: https://discuss.pytorch.org/t/issues-..., and https://github.com/pytorch/pytorch/is....

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-08-20 13:50:16 -0500

Seen: 563 times

Last updated: Aug 21 '21