‘boost::placeholders’ has not been declared : boost::placeholders::_1
I am trying to launch a ROS project but I receive a very strange error: ‘boost::placeholders’ has not been declared
.
I have the following settings:
1) Ubuntu 20.04
2) ROS Noetic
3) Boost 1.71
4) CMake
-> cmake version 3.16.3
Below a sample of the error I receive in the terminal:
In file included from /opt/ros/noetic/include/ros/node_handle.h:34,
from /opt/ros/noetic/include/ros/ros.h:45,
/opt/ros/noetic/include/ros/publisher.h: In member function ‘boost::function<void(const boost::shared_ptr<ros::SubscriberLink>&)> ros::Publisher::getLastMessageCallback()’:
/opt/ros/noetic/include/ros/publisher.h:179:70: error: ‘boost::placeholders’ has not been declared
179 | return boost::bind(&Impl::pushLastMessage, impl_.get(), boost::placeholders::_1);
Below the file that seems to carry this error is reported:
template<class M, class T>
Subscriber subscribe(const std::string& topic, uint32_t queue_size, void(T::*fp)(M), T* obj,
const TransportHints& transport_hints = TransportHints())
{
SubscribeOptions ops;
ops.template initByFullCallbackType<M>(topic, queue_size, boost::bind(fp, obj, boost::placeholders::_1));
ops.transport_hints = transport_hints;
return subscribe(ops);
}
Following this source I can confirm I added C++14
:
cmake_minimum_required(VERSION 2.8.3)
project(lidar_boat_detection)
set(CMAKE_BUILD_TYPE Debug)
add_compile_options(-std=c++14 -g)
find_package(PCL 1.8 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
find_package(Boost REQUIRED COMPONENTS
system
filesystem
date_time
thread
)
find_package(catkin REQUIRED COMPONENTS
roscpp
pcl_conversions
pcl_ros
std_msgs
message_generation
)
... Other modules and stuff
1) Following this source I can confirm I added
2) Also I consulted this source and I added #include <boost/bind/bind.hpp>
instead of #include <boost/bind.hpp>
as per new directive and I added using namespace boost::placeholders;
. However non of these solutions worked and another thing I tried was to add #include <boost/bind/placeholders.hpp>
and that also didn't work:
#ifndef ROSCPP_PUBLISHER_HANDLE_H
#define ROSCPP_PUBLISHER_HANDLE_H
#include "ros/forwards.h"
#include "ros/common.h"
#include "ros/message.h"
#include "ros/serialization.h"
//#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/thread/mutex.hpp>
using namespace boost::placeholders;
namespace ros
{
class NodeHandleBackingCollection;
....
}
3) Always from the same post I tried to add the following line #define BOOST_BIND_NO_PLACEHOLDERS
at the beginning of the file but that also didn't work:
#ifndef ROSCPP_PUBLISHER_HANDLE_H
#define ROSCPP_PUBLISHER_HANDLE_H
#define BOOST_BIND_NO_PLACEHOLDERS
#include "ros/forwards.h"
#include "ros/common.h"
#include "ros/message.h"
#include "ros/serialization.h"
//#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/thread/mutex.hpp>
using namespace boost::placeholders;
namespace ros
{
class NodeHandleBackingCollection;
....
}
4) I dug more and come across this post but unfortunately it was not useful to solve the problem.
5) This question would have been useful is a proper answer would have been provided as this is extremely close to the problem I have.
I am running out of ideas on how to solve it. Thanks for pointing in the right direction for solving this issue.
Please edit your question to show us the
subscribe()
call that is failing, and show us how the callback method you are trying to call is defined.Hello Mike, I am only trying to launch here
catkin_make
but that is not working. The error is coming from the ROS Library in the file/opt/ros/noetic/include/node_handle.h
,/opt/ros/noetic/include/topic.h
,/opt/ros/noetic/include/publisher.h
and/opt/ros/noetic/include/message_filters/simple_filter.h
. I also explained the problem here but no specific solution was found.Now with all my heart I wouldn't want to modify a ROS library, but it seems to me that this is the only way to hopefully have
catkin_make
working. It seems that a potential solution would be to replaceboost::placeholders::_1
found on the ROS Library header files I indicated above with_1
. Very bad way to do that but I currently have no other ideas...And it is also weird because on ROSMelodic
I never had this problems.You are jumping to conclusions. This is not a problem with any ros header files, it's a problem with the c++ file you are trying to compile. There is something wrong with the subscribe() call in the .cpp file, and if you read the whole error message it will tell which line of the .cpp file. If you don't show us that line of code, as I requested above, there is no help we can give you.
Ok Mike I understand. In order to make the problem even narrower I created a minimal verifiable ros node that exactly replicates the error I am talking about. If you have time please download it from my repo here. Also here I made a quick 1 min video where you can see the error real-time. I am using
Qt5
as editor. Thanks for shedding some light on this problem.Did you ever find a solution? I'm experiencing the very same issue. Edit: Nevermind.. I discovered that the package that was having issues was using it's own boost library and when I renamed the boost folder in its include to something else, everything built fine. I presume its library was not compatible with noetic or something.. Four hours down.