我正在将代码从 boost 1.67 移植到 boost 1.74 (debian buster->bullseye)。
\n当我编译时我得到:
\nIn file included from /usr/include/boost/config/header_deprecated.hpp:18,\n from /usr/include/boost/detail/no_exceptions_support.hpp:15,\n from /usr/include/boost/msm/back/state_machine.hpp:20,\n from /home/stew/mycode.cpp:3:\n/usr/include/boost/detail/no_exceptions_support.hpp:17:1: note: \xe2\x80\x98#pragma message: This header is deprecated. Use <boost/core/no_exceptions_support.hpp> instead.\xe2\x80\x99\n 17 | BOOST_HEADER_DEPRECATED("<boost/core/no_exceptions_support.hpp>")\n | ^~~~~~~~~~~~~~~~~~~~~~~\n/usr/include/boost/bind.hpp:36:1: note: \xe2\x80\x98#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.\xe2\x80\x99\n 36 | BOOST_PRAGMA_MESSAGE(\n | ^~~~~~~~~~~~~~~~~~~~\n
Run Code Online (Sandbox Code Playgroud)\n我知道标头已被弃用。我很高兴改变
\n#include <boost/bind.hpp> -> #include <boost/bind/bind.hpp>\n#include <boost/detail/no_exceptions_support.hpp> -> #include <boost/core/no_exceptions_support.hpp>\n
Run Code Online (Sandbox Code Playgroud)\n然而问题不在我的代码中。在里面<boost/msm/back/state_machine.hpp>
。对于包含任何这些标头的每个实例,我都会收到类似以下错误:
In file included from /usr/include/boost/bind.hpp:30,\n from /usr/include/boost/property_tree/json_parser/detail/parser.hpp:7,\n from /usr/include/boost/property_tree/json_parser/detail/read.hpp:13,\n from /usr/include/boost/property_tree/json_parser.hpp:16:\n/usr/include/boost/bind.hpp:36:1: note: \xe2\x80\x98#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.\xe2\x80\x99\n 36 | BOOST_PRAGMA_MESSAGE(\n | ^~~~~~~~~~~~~~~~~~~~\n\n\nIn file included from /usr/include/boost/math/tools/cxx03_warn.hpp:9,\n from /usr/include/boost/math/constants/constants.hpp:11:\n/usr/include/boost/bind.hpp:36:1: note: \xe2\x80\x98#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.\xe2\x80\x99\n 36 | BOOST_PRAGMA_MESSAGE(\n | ^~~~~~~~~~~~~~~~~~~~\n\n\nIn file included from /usr/include/boost/smart_ptr/detail/sp_thread_sleep.hpp:22,\n from /usr/include/boost/smart_ptr/detail/yield_k.hpp:23,\n from /usr/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14,\n from /usr/include/boost/smart_ptr/detail/spinlock.hpp:42,\n from /usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:25,\n from /usr/include/boost/smart_ptr/shared_ptr.hpp:29,\n from /usr/include/boost/shared_ptr.hpp:17,\n from /usr/include/boost/date_time/time_clock.hpp:17,\n from /usr/include/boost/date_time/posix_time/posix_time_types.hpp:10,\n from /usr/include/boost/asio/time_traits.hpp:23,\n from /usr/include/boost/asio/detail/timer_queue_ptime.hpp:22,\n from /usr/include/boost/asio/detail/deadline_timer_service.hpp:29,\n from /usr/include/boost/asio/basic_deadline_timer.hpp:25,\n from /usr/include/boost/asio.hpp:25:\n/usr/include/boost/bind.hpp:36:1: note: \xe2\x80\x98#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.\xe2\x80\x99\n 36 | BOOST_PRAGMA_MESSAGE(\n | ^~~~~~~~~~~~~~~~~~~~\n\n
Run Code Online (Sandbox Code Playgroud)\n有没有办法在不修补 boost 本身的情况下消除 boost 的内部警告?
\n我知道我可以避免-DBOOST_BIND_GLOBAL_PLACEHOLDERS
警告bind
,但是问题又如何呢detail/no_exceptions_support.hpp
?
小智 9
看看吧
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
Run Code Online (Sandbox Code Playgroud)
因此,将 -DBOOST_ALLOW_DEPRECATED_HEADERS 添加到编译标志中,并且不应再显示 boost 弃用警告。
我在我的 CMakeLists.txt 文件中执行此操作:
# ignore BOOST deprecated headers
add_definitions("-DBOOST_ALLOW_DEPRECATED_HEADERS")
add_definitions("-DBOOST_BIND_GLOBAL_PLACEHOLDERS")
Run Code Online (Sandbox Code Playgroud)
我的构建日志现在噪音少了很多(在我的例子中是 Ubuntu 22.04)
再见冈瑟