Ask Your Question

Revision history [back]

I encountered similar question when using pluginlib for loading my customized rviz panel, but I was using CMAKE_AUTOMOC for my qt objects. (Working on Ubuntu 14.04, ROS indigo)

My file system structure is like this:

pkg_folder

- config

- include/rviz_panel.h

- src/rviz_panel.cpp

- CMakeLists.txt

- package.xml

- package_description.xml

The core parts for add_library is:

catkin_package()

include_directories(include)

set(CMAKE_AUTOMOC ON)

set(HEADER_FILES include/FrameFabRvizPanel.h )

set(SRC_FILES src/FrameFabRvizPanel.cpp #src/FrameFab.cpp #src/FrameFabRenderWidget.cpp #src/WireFrame.cpp )

add_library(${PROJECT_NAME} ${SRC_FILES})

target_link_libraries( ${PROJECT_NAME} ${QT_LIBRARIES} ${catkin_LIBRARIES} )

Using this cmake file and package xml and description xml following official rviz plugin tutorial, I went through catkin_make process smoothly and harvest my lib_pkg.so successfully.

Then launching process for Rviz went on smoothly, and I can even see my panel in the add_new_panel list.

But when I click on it to open it, ROS pumped out an ERROR:

PluginlibFactory: The plugin for class 'framefab_mpp/FrameFabRvizPanel' failed to load. Error: Failed to load library /home/yijiangh/catkin_ws/devel/lib//libframefab_mpp.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 (Poco exception = /home/yijiangh/catkin_ws/devel/lib//libframefab_mpp.so: undefined symbol: _ZTVN8framefab17FrameFabRvizPanelE)

(Exactly the same symptom @mcholewi has encountered in his thread)

When using rospack plugins --attrib=plugin rviz, I can successfully see the plugin_description.xml address for my pkg.

After getting stuck for 3 days, I happened to see this thread in stackoverflow. And it just saved huge amount of my time!

So change my CMakeLists.txt file like this:

change this line:

add_library(${PROJECT_NAME} ${SRC_FILES})

into

add_library(${PROJECT_NAME} ${SRC_FILES} ${HEADER_FILES})

And everything just works like a charm.

I think the reason can be found at CMake AUTOMOC official doc:

If an #include statement like #include "moc_foo.cpp" is found, the Q_OBJECT class declaration is expected in the header, and moc is run on the header file. A moc_foo.cpp file will be generated from the source’s header into the CMAKE_CURRENT_BINARY_DIR directory. This allows the compiler to find the included moc_foo.cpp file regardless of the location the original source. However, if multiple source files in different directories do this then their generated moc files would collide. In this case a diagnostic will be issued.

So in my previous mistake, the QObject declaration cannot be found thus pluginlib found my customized panel (FrameFabRvizPanel in my case) is undefined.

Thus the solution would be:

  • You can put cpp and header files for your rviz related plugin together in one folder
  • or use the technique stated above (link both source and header to your created library)

I encountered similar question when using pluginlib for loading my customized rviz panel, but I was using CMAKE_AUTOMOC for my qt objects. (Working on Ubuntu 14.04, ROS indigo)

My file system structure is like this:

pkg_folder

- config

- include/rviz_panel.h

- src/rviz_panel.cpp

- CMakeLists.txt

- package.xml

- package_description.xml

pkg_folder
\-  config
\-  include/rviz_panel.h
\-  src/rviz_panel.cpp
\-  CMakeLists.txt
\-  package.xml
\-  package_description.xml

The core parts for add_library is:

catkin_package()

include_directories(include)

catkin_package()
include_directories(include)
set(CMAKE_AUTOMOC ON)

ON) set(HEADER_FILES include/FrameFabRvizPanel.h )

) set(SRC_FILES src/FrameFabRvizPanel.cpp #src/FrameFab.cpp #src/FrameFabRenderWidget.cpp #src/WireFrame.cpp )

add_library(${PROJECT_NAME} ${SRC_FILES})

) **add_library(${PROJECT_NAME} ${SRC_FILES})** target_link_libraries( ${PROJECT_NAME} ${QT_LIBRARIES} ${catkin_LIBRARIES} )

)

Using this cmake file and package xml and description xml following official rviz plugin tutorial, I went through catkin_make process smoothly and harvest my lib_pkg.so successfully.

Then launching process for Rviz went on smoothly, and I can even see my panel in the add_new_panel list.

But when I click on it to open it, ROS pumped out an ERROR:

PluginlibFactory: The plugin for class 'framefab_mpp/FrameFabRvizPanel' failed to load.  Error: Failed to load library /home/yijiangh/catkin_ws/devel/lib//libframefab_mpp.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 (Poco exception = /home/yijiangh/catkin_ws/devel/lib//libframefab_mpp.so: undefined symbol: _ZTVN8framefab17FrameFabRvizPanelE)

_ZTVN8framefab17FrameFabRvizPanelE)

(Exactly the same symptom @mcholewi has encountered in his thread)

When using rospack plugins --attrib=plugin rviz, rviz, I can successfully see the plugin_description.xml plugin_description.xml address for my pkg.

After getting stuck for 3 days, I happened to see this thread in stackoverflow. And it just saved huge amount of my time!

So change my CMakeLists.txt file like this:

change this line:

add_library(${PROJECT_NAME} ${SRC_FILES})

**add_library(${PROJECT_NAME} ${SRC_FILES})**

into

add_library(${PROJECT_NAME}

**add_library(${PROJECT_NAME} ${SRC_FILES} ${HEADER_FILES})

${HEADER_FILES})**

And everything just works like a charm.

I think the reason can be found at CMake AUTOMOC official doc:

If an #include statement like #include "moc_foo.cpp" is found, the Q_OBJECT class declaration is expected in the header, and moc is run on the header file. A moc_foo.cpp file will be generated from the source’s header into the CMAKE_CURRENT_BINARY_DIR directory. This allows the compiler to find the included moc_foo.cpp file regardless of the location the original source. However, if multiple source files in different directories do this then their generated moc files would collide. In this case a diagnostic will be issued.

So in my previous mistake, the QObject declaration cannot be found thus pluginlib found my customized panel (FrameFabRvizPanel in my case) is undefined.

Thus the solution would be:

  • You can put cpp and header files for your rviz related plugin together in one folder
  • or use the technique stated above (link both source and header to your created library)