c++ - 如何使内部 boost 已弃用的消息静音

标签 c++ boost

我正在将我的代码从 boost 1.67 移植到 boost 1.74(debian buster->bullseye)。
当我编译时,我得到:

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(
      | ^~~~~~~~~~~~~~~~~~~~
我知道标题已被弃用。我很高兴改变
#include <boost/bind.hpp>                         -> #include <boost/bind/bind.hpp>
#include <boost/detail/no_exceptions_support.hpp> -> #include <boost/core/no_exceptions_support.hpp>
但是问题不在我的代码中。它在 <boost/msm/back/state_machine.hpp> .对于包含任何这些 header 的每个实例,我都会收到这样的错误:
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(
      | ^~~~~~~~~~~~~~~~~~~~

有没有办法在不修补 boost 本身的情况下使 boost 的内部警告静音?
我知道我可以 -DBOOST_BIND_GLOBAL_PLACEHOLDERS避免 bind警告,但是 detail/no_exceptions_support.hpp 呢?问题?

最佳答案

你可以

  • 告诉库开发人员警告是破坏性的。 “下游”库应该更新以避免不推荐使用的接口(interface)
  • 查找单个消息的解决方法。例如。全局添加 BOOST_BIND_GLOBAL_PLACEHOLDERS定义将使所有 bind.hpp 静音警告。从技术上讲,您应该更喜欢使用 BOOST_BIND_NO_PLACEHOLDERS但有些库将不再工作(例如 Boost 属性树,至少对于某些后端而言)。
  • 关于c++ - 如何使内部 boost 已弃用的消息静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66906613/

    相关文章:

    c++ - 在 C++ 中再次运行时,rand() 不会更改值

    c++ - 多线程中的单例使用

    c++ - 指向对象数组的指针需要公共(public)析构函数

    python - 如何为 Python 创建 C++ 库

    multithreading - 如何取消(不终止) boost 线程?

    c++ - 导出的 C++ 类的 boost::hash_value 内联函数

    c++ - IplImage 上的半透明对象

    c++ - 在嵌套的 boost 绑定(bind)中使用模板函数

    C++ boost : Get time with milliseconds

    c++ - 使用 gzip_compressor 产生不同的文件大小