skip to Main Content

I’m porting my code from boost 1.67 to boost 1.74 (debian buster->bullseye).

When I compile I get:

In file included from /usr/include/boost/config/header_deprecated.hpp:18,
                 from /usr/include/boost/detail/no_exceptions_support.hpp:15,
                 from /usr/include/boost/msm/back/state_machine.hpp:20,
                 from /home/stew/mycode.cpp:3:
/usr/include/boost/detail/no_exceptions_support.hpp:17:1: note: ‘#pragma message: This header is deprecated. Use <boost/core/no_exceptions_support.hpp> instead.’
   17 | BOOST_HEADER_DEPRECATED("<boost/core/no_exceptions_support.hpp>")
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~

I get that headers get deprecated. I’m happy to change

#include <boost/bind.hpp>                         -> #include <boost/bind/bind.hpp>
#include <boost/detail/no_exceptions_support.hpp> -> #include <boost/core/no_exceptions_support.hpp>

However the problem isn’t in my code. It’s in <boost/msm/back/state_machine.hpp>. I’m getting errors like these for each instance of including any of these headers:

In file included from /usr/include/boost/bind.hpp:30,
                 from /usr/include/boost/property_tree/json_parser/detail/parser.hpp:7,
                 from /usr/include/boost/property_tree/json_parser/detail/read.hpp:13,
                 from /usr/include/boost/property_tree/json_parser.hpp:16:
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~


In file included from /usr/include/boost/math/tools/cxx03_warn.hpp:9,
                 from /usr/include/boost/math/constants/constants.hpp:11:
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~


In file included from /usr/include/boost/smart_ptr/detail/sp_thread_sleep.hpp:22,
                 from /usr/include/boost/smart_ptr/detail/yield_k.hpp:23,
                 from /usr/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14,
                 from /usr/include/boost/smart_ptr/detail/spinlock.hpp:42,
                 from /usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:25,
                 from /usr/include/boost/smart_ptr/shared_ptr.hpp:29,
                 from /usr/include/boost/shared_ptr.hpp:17,
                 from /usr/include/boost/date_time/time_clock.hpp:17,
                 from /usr/include/boost/date_time/posix_time/posix_time_types.hpp:10,
                 from /usr/include/boost/asio/time_traits.hpp:23,
                 from /usr/include/boost/asio/detail/timer_queue_ptime.hpp:22,
                 from /usr/include/boost/asio/detail/deadline_timer_service.hpp:29,
                 from /usr/include/boost/asio/basic_deadline_timer.hpp:25,
                 from /usr/include/boost/asio.hpp:25:
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~

Is there a way to silence boost’s internal warnings without patching boost itself?

I know I can -DBOOST_BIND_GLOBAL_PLACEHOLDERS to avoid the bind warning, but what about the detail/no_exceptions_support.hpp issue?

3

Answers


  1. You can

    • tell the library devs that the warnings are disruptive. The ‘downstream’ libraries should be updating to avoid the deprecated interface(s)

    • look up workarounds for individual messages. E.g. globally adding the BOOST_BIND_GLOBAL_PLACEHOLDERS define will silence all the bind.hpp warnings. Technically, you should prefer to use BOOST_BIND_NO_PLACEHOLDERS but some libraries wouldn’t work anymore (e.g. Boost Property Tree, at least for some backends).

    Login or Signup to reply.
  2. This has been driving me crazy too. I finally just modified the internally referenced boost include files per the instruction. In my case it was just four files and for most it was just a matter of commenting out unnecessary includes. The files I modified are

    • boostgeometryindexdetailvarray_detail.hpp
    • boostchronoiotime_point_io.hpp
    • boostchronoioduration_io.hpp
    • boostrangemetafunctions.hpp
    Login or Signup to reply.
  3. Just have a look at

    boost/config/header_deprecated.hpp:

    #ifndef BOOST_CONFIG_HEADER_DEPRECATED_HPP_INCLUDED
    #define BOOST_CONFIG_HEADER_DEPRECATED_HPP_INCLUDED
    
    //  Copyright 2017 Peter Dimov.
    //
    //  Distributed under the Boost Software License, Version 1.0.
    //
    //  See accompanying file LICENSE_1_0.txt or copy at
    //  http://www.boost.org/LICENSE_1_0.txt
    //
    //  BOOST_HEADER_DEPRECATED("<alternative>")
    //
    //  Expands to the equivalent of
    //    BOOST_PRAGMA_MESSAGE("This header is deprecated. Use <alternative> instead.")
    //
    //  Note that this header is C compatible.
    
    #include <boost/config/pragma_message.hpp>
    
    #if defined(BOOST_ALLOW_DEPRECATED_HEADERS)
    # define BOOST_HEADER_DEPRECATED(a)
    #else
    # define BOOST_HEADER_DEPRECATED(a) BOOST_PRAGMA_MESSAGE("This header is deprecated. Use " a " instead.")
    #endif
    
    #endif // BOOST_CONFIG_HEADER_DEPRECATED_HPP_INCLUDED
    

    So add -DBOOST_ALLOW_DEPRECATED_HEADERS to your compile flags and the boost deprecation warnings should no longer be shown.

    I am doing this in my CMakeLists.txt file:

      # ignore BOOST deprecated headers
      add_definitions("-DBOOST_ALLOW_DEPRECATED_HEADERS")
      add_definitions("-DBOOST_BIND_GLOBAL_PLACEHOLDERS")
    

    And my build log is a lot less noisy now (Ubuntu 22.04 in my case)

    Bye Gunther

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search