error: ‘_1’ was not declared in this scope
Hi.
I'm trying to use boost bind in my ROS 2 package. But I'm getting the following error when building with Colcon build:
error:‘_1’ was not declared in this scope
error:‘ _2’ was not declared in this scope
Here is my C++ code:
#include <functional>
#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include <message_filters/subscriber.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <message_filters/time_synchronizer.h>
#include "boost/bind/bind.hpp"
#include <functional>
void callback(const std_msgs::msg::String::SharedPtr& st_1,
const std_msgs::msg::String::SharedPtr& st_2) {
// Callback function...
}
int main(int argc, char** argv){
rclcpp::init(argc, argv);
auto node = rclcpp::Node::make_shared("my_node");
message_filters::Subscriber<std_msgs::msg::String> st_1(node, "st_1");
message_filters::Subscriber<std_msgs::msg::String> st_2(node, "st_2");
message_filters::TimeSynchronizer<std_msgs::msg::String, std_msgs::msg::String> sync(st_1, st_2, 10);
sync.registerCallback(boost::bind(&callback, _1, _2));
rclcpp::spin(node);
return 0;
}
CMakeFile:
cmake_minimum_required(VERSION 3.5)
project(project)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(message_filters REQUIRED)
find_package(Boost REQUIRED COMPONENTS
system
filesystem
date_time
thread
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()
add_executable(sub src/subscriber.cpp)
ament_target_dependencies(sub rclcpp std_msgs message_filters)
target_include_directories(sub PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(sub ${Boost_LIBRARIES})
install(TARGETS
sub
DESTINATION lib/${PROJECT_NAME})
ament_package()
Any help is welcome! Thanks!