Porting rviz plugin to rviz2 (cmake trouble)
I am trying to port a working rviz1 display plugin (ROS Kinetik) to rviz2 (ROS2 Crystal). I got pretty far, but now I am stuck at creating a shared ".so
" library with cmake to be used by rviz2. I end up with either a static ".a
" library or errors (which I assume are related to MOC file processing) during compilation. (I am not exactly a cmake wizard, so it may well be easy to solve.)
My pretty simplistic test workspace looks something like this:
src
└── traffic_sign_delegation_manager
├── icons [...]
├── images [...]
├── msg [...]
├── ui
│ ├── traffic_sign_delegation_manager_panel.ui
│ ├── traffic_sign_delegation_manager.qrc
│ └── traffic_sign_list_item.ui
├── CMakeLists.txt
├── package.xml
├── plugin_description.xml
├── adv_interaction_groupbox.cpp
├── adv_interaction_groupbox.h
├── draw_area.cpp
├── draw_area.h
├── traffic_sign_delegation_manager_display.cpp
├── traffic_sign_delegation_manager_display.h
├── traffic_sign_delegation_manager_panel.cpp
├── traffic_sign_delegation_manager_panel.h
└── ...
I converted my old catkin CMakeLists.txt
to the below one, by looking at the migration guide and the available plugins for rviz2. It does compile (via colcon build
), but it creates a static .a
library - and rviz2 wants a .so
library. These are the things I tried to fix it:
- If I add the
SHARED
keyword to theadd_library
command like this:add_library(delegator_lib SHARED ...)
, I get this strange error:/usr/bin/ld: cannot find -lXAW_LIBRARY-NOTFOUND
. Interestingly, in the catkin version, theSHARED
keyword was not necessary to get a.so
library. My feeling is that this is still the way to go... But why doesn't it work? - If I omit AUTO_MOC and do it the old-fashioned way (by uncommenting the
qt5_wrap_cpp
macros below), I end up withfatal error: ui_traffic_sign_delegation_manager_panel.h: No such file or directory
(and the same forui_traffic_sign_list_item.h
). - If I activate both AUTO_MOC and the old macro, I get a
multiple_instances
error for the four MOC files - which makes sense...
At this point, I have no idea what else to try. I'd be very grateful for ANY suggestions!
(I'm on Ubuntu xenial 16.04.)
CMakeLists.txt:
project(traffic_sign_delegation_manager)
set(CMAKE_CXX_STANDARD 17)
if(NOT WIN32)
add_definitions(-fPIC)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Wno-deprecated-declarations)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_common REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rosidl_generator_cpp)
find_package(pluginlib REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5OpenGL REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Widgets)
set(msg_files
"msg/TrafficSignList.msg"
"msg/TrafficSign.msg"
"msg/TrafficSignSetList.msg"
"msg/TrafficSignSet.msg"
"msg/TrafficSignSetStatus.msg"
"msg/TrafficSignsManaged.msg"
"msg/AccLever2.msg"
"msg/VehicleOdometry.msg"
)
rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
DEPENDENCIES std_msgs
)
link_directories(${ament_cmake_LIBRARY_DIRS})
add_definitions(-DQT_NO_KEYWORDS)
qt5_wrap_ui(QT_UI_FILES ui/traffic_sign_delegation_manager_panel.ui)
qt5_wrap_ui(QT_UI_FILES ui/traffic_sign_list_item.ui)
#qt5_wrap_cpp(MOC_FILES
# traffic_sign_delegation_manager_panel.h
# traffic_sign_delegation_manager_display.h
# adv_interaction_groupbox.h
# draw_area.h
#)
qt5_add_resources(QT_QRC_FILES ui/traffic_sign_delegation_manager.qrc)
set_property(SOURCE traffic_sign_delegation_manager_panel.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE draw_area.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE adv_interaction_groupbox.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE traffic_sign_delegation_manager_display.h PROPERTY SKIP_AUTOMOC ON)
add_library(delegator_lib # SHARED
vec2d.cpp
vec2d.h
traffic_sign_delegation_manager_panel.cpp
traffic_sign_delegation_manager_panel.h
draw_area.cpp
draw_area.h
traffic_sign_delegation_manager_display.cpp
traffic_sign_delegation_manager_display.h
adv_interaction_groupbox.cpp
adv_interaction_groupbox.h
ui/traffic_sign_list_item.ui
ui/traffic_sign_delegation_manager_panel.ui
${QT_UI_FILES}
${MOC_FILES}
)
rosidl_target_interfaces(delegator_lib ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_include_directories ...