由于未定义的符号,无法在凉亭中加载插件时出错

Error with failing to load plugin in gazebo because of undefined symbol

当我运行“roslaunch”时出现错误:

[Err] [Plugin.hh:178] Failed to load plugin libmodel_push.so: /Robosub_Simulation/devel/lib/libmodel_push.so: undefined symbol: _ZN9ModelPush14SetJointStatesERKN5boost10shared_ptrIKN11sensor_msgs11JointState_ISaIvEEEEE
Can you guys please assist us with how to solve this error?

这可能与包含库有关

#include <sensor_msgs/JointState.h>

并在名为 model_push.cpp:

的插件的函数中使用它
void ModelPush::addSubscribeForce()
{
    // ros::init("talker");

    ros::NodeHandle* rosnode = new ros::NodeHandle();
    ros::SubscribeOptions jointStatesSo = ros::SubscribeOptions::create<sensor_msgs::JointState>("/test", 1, SetJointStates,ros::VoidPtr(), rosnode->getCallbackQueue());
    ros::Subscriber subJointState = rosnode->subscribe(jointStatesSo);
    ros::spin();
}

static void SetJointStates(const sensor_msgs::JointState::ConstPtr &_js)
{
  static ros::Time startTime = ros::Time::now();
  {
    std::cout<<"AYo"<<std::endl;
  }
}

最后,因为这是一个链接器错误,所以这里是插件文件夹中的 CMakeLists.txt:

add_library(model_push SHARED model_push_plugin.cpp model_push.cpp)
add_dependencies(model_push ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(model_push ${catkin_LIBRARIES} ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES})

我已经尝试使用 QT5_WRAP_CPP 代替添加依赖项(来自 https://answers.gazebosim.org/question/25672/gui-plugin-linker-error-undefined-symbol/) however that leads to the same error. Also, for some context, this code (please see the repository https://github.com/GU-RoboSub-Machine-Learning/Robosub_Simulation/tree/ros_listener) is meant to subscribe to a node called "test" and is based off this tutorial for subscribing to joint commands: http://gazebosim.org/tutorials?tut=drcsim_ros_cmds&cat=drcsim。请大家提供有关如何正确实施 sensor_msgs/JointState 以避免错误的建议,如本文开头所示 post?

正如@Tsyvarev 所建议的,我在 SetJointStates 函数声明之前放置了“ModelPush::”。所以它看起来像下面这样:

void ModelPush::SetJointStates(const sensor_msgs::JointState::ConstPtr &_js)
{
  static ros::Time startTime = ros::Time::now();
  {
    std::cout<<"AYo"<<std::endl;
  }
}

这消除了错误,但是弹出了另一个错误,但与代码中 gazebo 订阅者的实现有关。那个单独的错误可能会在另一个堆栈溢出中 post.

旁注:为此使用 static 时出错,请注意我如何不将函数声明声明为 static。但是,我将 model_push.h 中的函数声明为静态的,如下所示:

static void SetJointStates(const sensor_msgs::JointState::ConstPtr);