ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Ros2, undefined reference to `message_filters::Connection::disconnect()

asked 2022-11-27 23:02:44 -0500

damiano gravatar image

updated 2022-11-27 23:34:18 -0500

Hello,

I am trying to build a node that subscribes to two topics using message_filters::Synchronizer with approximate policy. Here is the relevant part of my code:

MonocularSlamNode::MonocularSlamNode(ORB_SLAM2::System* pSLAM, const string &strVocFile, const string &strSettingsFile, const string &strSensor)
:   Node("orbslam"),
    m_SLAM(pSLAM)
{

message_filters::Subscriber<ImageMsg> image_sub_;
message_filters::Subscriber<ImageMsg> depth_sub_;              

image_sub_.subscribe(this, "camera");
depth_sub_.subscribe(this, "depth_map");
typedef message_filters::sync_policies::ApproximateTime<ImageMsg, ImageMsg> approximate_policy;
message_filters::Synchronizer<approximate_policy>syncApproximate(approximate_policy(10), image_sub_, depth_sub_);
syncApproximate.registerCallback(&MonocularSlamNode::GrabRGBD,this);
}

And then the callback function, just for reference:

    void MonocularSlamNode::GrabRGBD(const ImageMsg::SharedPtr msgIm, const ImageMsg::SharedPtr msgD)
{
// Copy the ros image message to cv::Mat.
try
{
    m_cvImPtr = cv_bridge::toCvCopy(msgIm);
}
catch (cv_bridge::Exception& e)
{
    RCLCPP_ERROR(this->get_logger(), "cv_bridge exception: %s", e.what());
    return;
}

// Copy the ros image message to cv::Mat.
try
{
    m_cvDPtr = cv_bridge::toCvCopy(msgD);
}
catch (cv_bridge::Exception& e)
{
    RCLCPP_ERROR(this->get_logger(), "cv_bridge exception: %s", e.what());
    return;
}

//rclcpp::Time now = this->get_clock()->now();
cout << m_cvImPtr->header.stamp.sec << " " << m_cvDPtr->header.stamp.sec << endl;
Tcw = m_SLAM->TrackRGBD(m_cvImPtr->image, m_cvDPtr->image, m_cvImPtr->header.stamp.sec);
}

The problem is, when I try to compile with colcon build, I get the following errors:

    /usr/bin/ld: CMakeFiles/mono.dir/src/monocular/monocular-slam-node.cpp.o: in function `message_filters::Synchronizer<message_filters::sync_policies::ApproximateTime<sensor_msgs::msg::Image_<std::allocator<void> >, sensor_msgs::msg::Image_<std::allocator<void> >, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType> >::disconnectAll()':
monocular-slam-node.cpp:(.text._ZN15message_filters12SynchronizerINS_13sync_policies15ApproximateTimeIN11sensor_msgs3msg6Image_ISaIvEEES7_NS_8NullTypeES8_S8_S8_S8_S8_S8_EEE13disconnectAllEv[_ZN15message_filters12SynchronizerINS_13sync_policies15ApproximateTimeIN11sensor_msgs3msg6Image_ISaIvEEES7_NS_8NullTypeES8_S8_S8_S8_S8_S8_EEE13disconnectAllEv]+0x38): undefined reference to `message_filters::Connection::disconnect()'
/usr/bin/ld: CMakeFiles/mono.dir/src/monocular/monocular-slam-node.cpp.o: in function `message_filters::Connection message_filters::Signal9<sensor_msgs::msg::Image_<std::allocator<void> >, sensor_msgs::msg::Image_<std::allocator<void> >, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType, message_filters::NullType>::addCallback<std::shared_ptr<sensor_msgs::msg::Image_<std::allocator<void> > >, std::shared_ptr<sensor_msgs::msg::Image_<std::allocator<void> > >, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&>(std::function<void (std::shared_ptr<sensor_msgs::msg::Image_<std::allocator<void> > >, std::shared_ptr<sensor_msgs::msg::Image_<std::allocator<void> > >, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&, std::shared_ptr<message_filters::NullType const> const&)> const&)':
monocular-slam-node.cpp:(.text._ZN15message_filters7Signal9IN11sensor_msgs3msg6Image_ISaIvEEES5_NS_8NullTypeES6_S6_S6_S6_S6_S6_E11addCallbackISt10shared_ptrIS5_ESA_RKS9_IKS6_ESE_SE_SE_SE_SE_SE_EENS_10ConnectionERKSt8functionIFvT_T0_T1_T2_T3_T4_T5_T6_T7_EE[_ZN15message_filters7Signal9IN11sensor_msgs3msg6Image_ISaIvEEES5_NS_8NullTypeES6_S6_S6_S6_S6_S6_E11addCallbackISt10shared_ptrIS5_ESA_RKS9_IKS6_ESE_SE_SE_SE_SE_SE_EENS_10ConnectionERKSt8functionIFvT_T0_T1_T2_T3_T4_T5_T6_T7_EE]+0x17a): undefined reference to `message_filters::Connection::Connection(std::function<void ()> const&)'
/usr/bin/ld: CMakeFiles/mono.dir/src/monocular/monocular-slam-node.cpp.o: in function `message_filters::Connection message_filters::SimpleFilter<sensor_msgs::msg::Image_<std::allocator<void> > >::registerCallback<message_filters::MessageEvent<sensor_msgs::msg::Image_<std::allocator<void> > const> const&>(std::function<void (message_filters::MessageEvent<sensor_msgs::msg::Image_<std::allocator<void> > const> const&)> const&)':
monocular-slam-node.cpp:(.text._ZN15message_filters12SimpleFilterIN11sensor_msgs3msg6Image_ISaIvEEEE16registerCallbackIRKNS_12MessageEventIKS5_EEEENS_10ConnectionERKSt8functionIFvT_EE[_ZN15message_filters12SimpleFilterIN11sensor_msgs3msg6Image_ISaIvEEEE16registerCallbackIRKNS_12MessageEventIKS5_EEEENS_10ConnectionERKSt8functionIFvT_EE]+0xb8): undefined reference to `message_filters::Connection::Connection(std::function<void ()> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mono.dir/build.make:192: mono] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/mono.dir/all] Error 2

Which I don't really understand at all, as it does not refer to specific lines ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-27 23:38:43 -0500

damiano gravatar image

Ok, found the answer by myself.

In the CMakeList.txt file, changed the following line:

ament_target_dependencies(mono rclcpp sensor_msgs visualization_msgs cv_bridge ORB_SLAM2 Boost)

into:

ament_target_dependencies(mono rclcpp sensor_msgs visualization_msgs message_filters cv_bridge ORB_SLAM2 Boost)

Now it compiles correctly.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-11-27 23:02:44 -0500

Seen: 285 times

Last updated: Nov 27 '22