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

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

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

RayROS gravatar image

updated 2022-08-17 11:48:12 -0500

lucasw gravatar image

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.

edit retag flag offensive close merge delete

Comments

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
1

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

2 Answers

Sort by » oldest newest most voted
0

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

Mike Scheutzow gravatar image

Remove this line from your CMakeLists.txt file:

add_definitions(-DBOOST_BIND_NO_PLACEHOLDERS)

edit flag offensive delete link more

Comments

1

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
1

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

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

answered 2022-08-17 10:46:59 -0500

bhomaidan gravatar image

I have solved this problem in my case as follows:

  1. Removed Boost 1.71 completely as explained here (not sure if this step is necessary).
  2. Installed Boost 1.80 from source:

    sudo ./bootstrap.sh --with-libraries=atomic,chrono,container,context,contract,coroutine,date_time,exception,fiber,filesystem,graph,graph_parallel,headers,iostreams,json,locale,log,math,mpi,nowide,program_options,python,random,regex,serialization,stacktrace,system,test,thread,timer,type_erasure,wave --exec-prefix=/usr/local --libdir=/usr/local/lib --includedir=/usr/local/lib
    

    and then sudo ./b2

  3. Reinstalled ROS : sudo apt install ros-noetic-desktop-full as it was removed by step 1

  4. Reinstalled Ubuntu Desktop sudo apt-get install ubuntu-desktop as it was removed by step 1
  5. Changed the CPP standard to C++14 : catkin config -DCMAKE_CXX_FLAGS=-std=c++14 (not sure if necessary)

And after reboot everything worked well. I'm getting many warnings, but no errors!

edit flag offensive delete link more

Question Tools

2 followers

Stats

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

Seen: 2,266 times

Last updated: Aug 17 '22