ROS Noetic Issue with linking with LibTorch and class_loader
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!
Please provide enough information to reproduce your problem otherwise it's very hard to help you.
I updated the post. Thanks for help!