Launch a new rviz plugin failed, Error:Failed to load library XXX.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. [closed]

asked 2017-11-29 07:34:27 -0600

tengfei gravatar image

Hi all. I'm trying to write a rviz plugin which is a panel and output the joint_state of my robot.I foolow the tutorial in Mastering ROS for Robotics Programmingchapter 6. After catkin_make successfully, I wanted to load it in rviz panel.But when I chose it, there was an erroe output like this:

The class required for this panel, 'joint_value_monitor/joint_value', could not be loaded.
Error:
Failed to load library /home/shantengfei/catkin_ws/devel/lib//libjoint_value_monitor.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/shantengfei/catkin_ws/devel/lib//libjoint_value_monitor.so: undefined symbol: _ZN19joint_value_monitor11joint_value4loadERKN4rviz6ConfigE)

this is my package tree:

    .
├── CMakeLists.txt
├── include
│   └── joint_value_monitor
│       └── joint_value.h
├── package.xml
├── plugin_description.xml
└── src
    └── joint_value.cpp

my package.xml:

<?xml version="1.0"?>
<!--package format="2"-->
<package format="2">
  <name>joint_value_monitor</name>
  <version>0.0.0</version>
  <description>The joint_value_monitor package</description>

  <maintainer email="shantengfei@todo.todo">shantengfei</maintainer>


  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rviz</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>rviz</build_export_depend>
  <build_export_depend>sensor_msgs</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>

  <exec_depend>roscpp</exec_depend>
  <exec_depend>rviz</exec_depend>
  <exec_depend>sensor_msgs</exec_depend>
  <exec_depend>std_msgs</exec_depend>

  <!-- The export tag contains other, unspecified, tags -->
  <export>
      <rviz plugin="${prefix}/plugin_description.xml"/>
  </export>
</package>

my plugin_description.xml:

<library path="lib/libjoint_value_monitor">
  <class name="joint_value_monitor/joint_value"
         type="joint_value_monitor::joint_value"
         base_class_type="rviz::Panel">
    <description>
      A panel widget allowing simple diff-drive style robot base control.
    </description>
  </class>
</library>

my CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)
project(joint_value_monitor)

## Compile as C++11, supported in ROS Kinetic and newer
 add_compile_options(-std=c++11)
##原cmake文件
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rviz
  sensor_msgs
  std_msgs
)

#原cmake文件
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES joint_value_monitor
#  CATKIN_DEPENDS roscpp rviz sensor_msgs std_msgs
#  DEPENDS system_lib
)

#原cmake文件
include_directories(
  include ${catkin_INCLUDE_DIRS}
# include
  ${catkin_INCLUDE_DIRS}
)
link_directories(${catkin_LIBRARY_DIRS})

find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include(${QT_USE_FILE})

add_definitions(-DQT_NO_KEYWORDS)
qt4_wrap_cpp(MOC_FILES
  include/joint_value_monitor/joint_value.h
)
set(SOURCE_FILES
  src/joint_value.cpp 
  ${MOC_FILES}
)
add_library(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${catkin_LIBRARIES})

install(TARGETS
  ${PROJECT_NAME}
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(FILES 
  plugin_description.xml
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

my joint_value.h

#ifndef JOINT_VALUE_H
#define JOINT_VALUE_H

#include <ros/ros.h>
#include <ros/console.h>

#include <rviz/panel.h> //plugin基类的头文件
#include <sensor_msgs/JointState.h>
#include <QLabel>
class QLineEdit;

namespace joint_value_monitor
{

class joint_value : public rviz::Panel
 {
  // 后边需要用到Qt的信号和槽,都是QObject的子类,所以需要声明Q_OBJECT宏
  Q_OBJECT

public:
  // 构造函数,在类中会用到QWidget的实例来实现GUI界面,这里先初始化为0即可
 joint_value(QWidget *parent = 0);

 // 重载rviz::Panel积累中的函数,用于保存、加载配置文件中的数据,在我们这个plugin
 // 中,数据就是topic的名称 
 //这里还是不知道怎么用
 virtual void load(const rviz::Config &config);
 virtual void save(rviz::Config config) const;

 //公共槽

 //内部槽
 protected Q_SLOTS:
 void update_joint_value();
protected:
  void chatterCB(const sensor_msgs::JointState& msg);
      //内部变量,各个关节的实际数据,使用QLabel来显示
QLabel *QLjoint1;
QLabel* QLjoint2;
QLabel *QLjoint3;
QLabel *QLjoint4;
QLabel *QLjoint5;

QLabel *QLjoint6;
QString joint1Value;
QString joint2Value;
QString joint3Value;
QString joint4Value;
QString joint5Value;
QString joint6Value;

 double joint1{0};
 double joint2{0};
 double joint3{0};
 double joint4{0};
 double joint5{0};
 double joint6{0};

 ros::Subscriber sub;
 ros::NodeHandle nh_;

};
} // end of namespace joint_value_monitor
#endif ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tengfei
close date 2017-12-06 23:42:35.130584

Comments

Hi @tengfei, did you resolve your problem? If yes, may you please describe how?

adroit89 gravatar imageadroit89 ( 2018-05-22 09:22:35 -0600 )edit

I've exactly the same error. Does someone have the answer please ?

Hillal gravatar imageHillal ( 2019-06-21 09:24:55 -0600 )edit