Ask Your Question

‘boost::placeholders’ has not been declared : boost::placeholders::_1

asked 2021-07-16 13:58:05 -0500

RayROS gravatar image

updated 2021-07-16 14:41:11 -0500

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)
add_compile_options(-std=c++14 -g)

find_package(PCL 1.8 REQUIRED)


find_package(Boost REQUIRED COMPONENTS 

find_package(catkin REQUIRED COMPONENTS 

    ... 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:


#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:



#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.

edit retag flag offensive close merge delete


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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-07-17 08:54:15 -0500 )edit

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.

RayROS gravatar image RayROS  ( 2021-07-17 10:17:47 -0500 )edit

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 replace boost::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 ROS Melodic I never had this problems.

RayROS gravatar image RayROS  ( 2021-07-17 10:20:36 -0500 )edit

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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-07-17 10:49:35 -0500 )edit

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.

RayROS gravatar image RayROS  ( 2021-07-17 12:58:54 -0500 )edit

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.

madgrizzle gravatar image madgrizzle  ( 2021-09-19 20:04:22 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-07-17 14:09:34 -0500

Mike Scheutzow gravatar image

Remove this line from your CMakeLists.txt file:


edit flag offensive delete link more


Thanks for looking. Unfortunately it is not working. I get the same error...

RayROS gravatar image RayROS  ( 2021-07-17 14:18:39 -0500 )edit

See video with that option commented.

RayROS gravatar image RayROS  ( 2021-07-17 14:25:15 -0500 )edit

You deleted devel and build dirs in the top level catkin_ws dir? This is a good idea when changing any thing inside a CMakeLists.txtfile.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-07-17 14:40:02 -0500 )edit

Yes I did try that too yesterday but didn't work too.

RayROS gravatar image RayROS  ( 2021-07-17 14:55:46 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-07-16 13:58:05 -0500

Seen: 717 times

Last updated: Jul 17 '21