Boost程序选项使用已弃用的功能。

5
我已经通过vcpkg安装了boost-program-options版本1.78。当我使用clang++-std=c++20进行编译时,会出现以下错误。但是当我使用g++进行编译时,不会出现这种情况。根据此链接std::unary_function自C++11以来已被弃用。
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/program_options/variables_map.hpp:12:
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/any.hpp:20:
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/type_index.hpp:29:
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/type_index/stl_type_index.hpp:47:
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:132:33: warning: 'unary_function<const std::error_category *, unsigned long>' is deprecated [-Wdeprecated-declarations]
        struct hash_base : std::unary_function<T, std::size_t> {};
                                ^
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:692:18: note: in instantiation of template class 'boost::hash_detail::hash_base<const std::error_category *>' requested here
        : public boost::hash_detail::hash_base<T*>
                 ^
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:420:24: note: in instantiation of template class 'boost::hash<const std::error_category *>' requested here
        boost::hash<T> hasher;
                       ^
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:551:9: note: in instantiation of function template specialization 'boost::hash_combine<const std::error_category *>' requested here
        hash_combine(seed, &v.category());
        ^
/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/stl_function.h:124:7: note: 'unary_function<const std::error_category *, unsigned long>' has been explicitly marked deprecated here
    } _GLIBCXX11_DEPRECATED;
      ^
/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/x86_64-redhat-linux/bits/c++config.h:2340:32: note: expanded from macro '_GLIBCXX11_DEPRECATED'
# define _GLIBCXX11_DEPRECATED _GLIBCXX_DEPRECATED
                               ^
/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/x86_64-redhat-linux/bits/c++config.h:2331:46: note: expanded from macro '_GLIBCXX_DEPRECATED'
# define _GLIBCXX_DEPRECATED __attribute__ ((__deprecated__))

为什么boost库使用被废弃的标准部分?忽略这些警告并使用-Wno-deprecated-declarations是否有错误?


2
Boost 不仅支持最新的 C++ 标准,还支持旧版本的 C++ 标准(尽管并非所有 Boost 组件库都支持所有 C++ 标准,例如 Signals2)。当前版本的 Boost 是 1.80,在您使用的组件库中可能具有更好的支持。 - Eljay
1个回答

5

自Boost 1.64 for MSVC (commit)和1.73 for其他编译器(commit)起,由于编译器/标准库不再支持,std::unary_function的使用已被替换。

但只要未检测到已删除,它仍将默认使用std::unary_function

自Boost 1.80起,当使用C++11或更高版本的libstdc++(commitissue)时,禁用了std::unary_function的使用,以消除弃用警告。类似的补丁已合并到libc++中(commitissue)。后者似乎未包含在最新的1.80版本中。
因此,您可以等待/升级到最新版本的Boost,手动添加补丁,或将头文件配置为系统头文件,以便通常抑制对它们的警告。(我不确定在您的设置中是否完全可能。)或者,使用您显示的标志禁用弃用警告,但这似乎是笨重的。
在使用C++17模式或更高版本编译时,如果函数已被完全移除,则可能有所帮助(未经测试)。
只需在包含任何boost头文件之前定义宏BOOST_NO_CXX98_FUNCTION_BASE也可能有所帮助,但我无法确定是否打算让用户这样做,或者它是否会破坏其他boost内容。我也可能不知道它是否会悄悄地破坏ABI。

我想最好还是忍受这个警告,直到vcpkg仓库更新。谢谢! - David Carpenter
GitHub表示,禁用libc++是在1.83.0标签中进行的,因此不包含在1.80.0版本中。 - undefined
@James 我写道这个功能在1.80版本中没有包含,而那是我写这篇文章时的最新版本。这个提交还有1.81的标签,所以应该在那个版本中包含了。我已经相应地调整了答案。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接