RVIZ2 plugin fails to load
Hello,
I am currently developing a rviz2 panel. Somehow I can not manage to load a minimalist version of a panel. Pluginlib seems to be able to find the library but I always encounter the following error:
[ERROR] [1631188327.522072850] [rviz2]: PluginlibFactory: The plugin for class 'autde_tello_panel/AutdeTello' failed to load. Error: Failed to load library /home/philly/projects/drone_poc/ros2_ws/install/autde_tello_panel/lib/libautde_tello_panel.so. Make sure that you are calling the PLUGINLIB_EXPORT_CLASS macro in the library code, and that names are consistent between this macro and your XML. Error string: Could not load library LoadLibrary error: /home/philly/projects/drone_poc/ros2_ws/install/autde_tello_panel/lib/libautde_tello_panel.so: undefined symbol: _ZTVN17autde_tello_panel15AutdeTelloPanelE, at /tmp/binarydeb/ros-foxy-rcutils-1.1.3/src/shared_library.c:84
I have checked the macro and the xml hundreds of times but it is still not working.
The header: autde_tello_panel.h:
#ifndef AUTDETELLOPANEL_H
#define AUTDETELLOPANEL_H
#include <QMainWindow>
#include "rviz_common/panel.hpp"
namespace rviz_common
{
namespace properties
{
class PropertyTreeWidget;
}
}
namespace autde_tello_panel
{
class AutdeTelloPanel : public rviz_common::Panel // QMainWindow
{
Q_OBJECT
public:
explicit AutdeTelloPanel(QWidget *parent = nullptr);
void onInitialize() override;
private:
rviz_common::properties::PropertyTreeWidget * tree_widget_;
};
} // namespace autde_tello_panel
#endif // AUTDETELLOPANEL_H
The source file: autde_tello_panel.cpp:
#include "autde_tello_panel/autde_tello_panel.h"
#include "rviz_common/properties/property_tree_widget.hpp"
#include "rviz_common/interaction/selection_manager.hpp"
#include "rviz_common/visualization_manager.hpp"
#include <QVBoxLayout>
namespace autde_tello_panel
{
AutdeTelloPanel::AutdeTelloPanel(QWidget *parent)
: rviz_common::Panel(parent)
{
auto layout = new QVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
tree_widget_ = new rviz_common::properties::PropertyTreeWidget();
layout->addWidget(tree_widget_);
setLayout(layout);
}
void AutdeTelloPanel::onInitialize()
{
tree_widget_->setModel(getDisplayContext()->getSelectionManager()->getPropertyModel());
}
} // namespace autde_tello_panel
#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(autde_tello_panel::AutdeTelloPanel, rviz_common::Panel)
plugin_description.xml
<library path="libautde_tello_panel">
<class name="autde_tello_panel/AutdeTello"
type="autde_tello_panel::AutdeTelloPanel"
base_class_type="rviz_common::Panel">
<description>
autde_tello_panel
</description>
</class>
</library>
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(autde_tello_panel LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(Qt5 COMPONENTS Widgets Core Gui REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_common REQUIRED)
find_package(pluginlib REQUIRED)
add_library(autde_tello_panel SHARED
src/autde_tello_panel.cpp
)
target_include_directories(autde_tello_panel PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${Qt5Widgets_INCLUDE_DIRS}
)
target_link_libraries(autde_tello_panel PUBLIC ${QT_LIBRARIES})
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(autde_tello_panel PRIVATE "RVIZ_DEFAULT_PLUGINS_BUILDING_LIBRARY")
# prevent pluginlib from using boost
target_compile_definitions(autde_tello_panel PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
pluginlib_export_plugin_description_file(rviz_common src/plugin_description.xml)
ament_target_dependencies(autde_tello_panel PUBLIC
rclcpp
rviz_common
)
ament_export_include_directories(include)
ament_export_targets(autde_tello_panel HAS_LIBRARY_TARGET)
ament_export_dependencies(
rviz_common
rclcpp
)
install(
TARGETS autde_tello_panel
EXPORT autde_tello_panel
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(
DIRECTORY include/
DESTINATION include
)
ament_package()
package.xml:
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>autde_tello_panel</name>
<version>0.0.0</version>
<description>Panel for rviz2</description>
<maintainer email="p.d">p.d</maintainer>
<license>all rights reserved</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>qtbase5-dev</build_depend>
<build_depend>qt5-qmake</build_depend>
<exec_depend>libqt5-core</exec_depend>
<depend>rclcpp</depend>
<depend>rviz_common</depend>
<depend>libqt5-widgets</depend>
<depend>rviz2</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<rviz plugin="plugin_description.xml"/> ...
I meet the same problem, had you solve it?
I did. I will add the answer below