When I run "roslaunch" there is the error:
[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?
This probably has to do with including the library
#include <sensor_msgs/JointState.h>
and using it in the functions for the plugin called 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;
}
}
Lastly because this is a linker error here is the CMakeLists.txt that is in the plugin folder:
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})
I have already tried using QT5_WRAP_CPP instead for adding the dependencies (from 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. Can guys you please provide suggestions on how to implement sensor_msgs/JointState correctly to not have the error, as shown in the beginning of this post?
As @Tsyvarev recommended I put "ModelPush::" before the SetJointStates function declaration. So it looks like this below:
void ModelPush::SetJointStates(const sensor_msgs::JointState::ConstPtr &_js)
{
static ros::Time startTime = ros::Time::now();
{
std::cout<<"AYo"<<std::endl;
}
}
This got rid of the error however there is another error that popped up but is related to the implementation of a gazebo subscriber in the code. That separate error will probably be in another stack overflow post.
Side Note: there was an error with using static for this and notice how I do not declare the function declaration as static. However, I do declare the function in the model_push.h as static as shown here:
static void SetJointStates(const sensor_msgs::JointState::ConstPtr);