如何解决构建 Boost Beast 示例 websocket_server_sync 时的编译错误
我正在尝试使用 Boost Beast 示例中的 websocket-server-sync 示例构建 Boost。首先,我想说我正在使用 MSVS 2017 专业版 15.3.5 和 SDK 版本 10.0.14393.0 在 Windows 10 上构建。我构建 Boost 的步骤如下:
首先我当然是从 bootstrap.cmd
开始,然后我运行 .\b2 variant=release variant=debug link=static threading=multi address-model=64
来构建静态 Boost 库。运行这两个步骤就成功了。
下一步是设置 Visual Studio 解决方案以运行 Boost Beast 示例。为了能够做到这一点,我需要调用 cmake bulding 系统。因此,我在 \libs\beast 中创建了 build 文件夹并运行了命令 cmake -G "Visual Studio 15 2017 Win64" ..
,它为 Visual Studio 创建了所需的解决方案。 cmake 过程成功。这里的日志:
-- Selecting Windows SDK version 10.0.14393.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.11.25508.2
-- The CXX compiler identification is MSVC 19.11.25508.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/winapp/MSVS2017PRO/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/winapp/MSVS2017PRO/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: optimized;C:/drive_d/programming/projects/cpp/3rdparty/external/lib/libcrypto.lib;debug;C:/drive_d/programming/projects/cpp/3rdparty/external/lib/libcryptod.lib (found version "1.1.0i")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/drive_d/programming/projects/cpp/3rdparty/boost_1_75_0/libs/beast/build
我在 Visual Studio 中启动了解决方案并尝试构建项目“websocket-server-sync”(配置:调试 | 平台:x64)并出现以下错误:
...
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/buffer_traits.hpp(123): error C2668: 'boost::asio::buffer_sequence_begin': ambiguous call to overloaded function
...
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/impl/buffers_cat.hpp(127): error C3546: '...': there are no parameter packs available to expand
...
整个 Visual Studio 构建输出如下。从日志可以看出错误发生在lib-beast和websocket-server-sync项目中(websocket-server-sync依赖于解决方案中包含的lib-beast和lib-asio项目):
1>------ Rebuild All started: Project: ZERO_CHECK,Configuration: Debug x64 ------
1>Checking Build System
2>------ Rebuild All started: Project: lib-asio,Configuration: Debug x64 ------
2>Building Custom Rule C:/drive_d/programming/projects/cpp/3rdparty/boost_1_75_0/libs/beast/CMakeLists.txt
2>lib_asio.cpp
2>lib-asio.vcxproj -> C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\libs\beast\build\Debug\lib-asio.lib
3>------ Rebuild All started: Project: lib-beast,Configuration: Debug x64 ------
3>Building Custom Rule C:/drive_d/programming/projects/cpp/3rdparty/boost_1_75_0/libs/beast/CMakeLists.txt
3>lib_beast.cpp
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/buffer_traits.hpp(123): error C2668: 'boost::asio::buffer_sequence_begin': ambiguous call to overloaded function
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/buffer.hpp(399): note: Could be 'const boost::asio::const_buffer *boost::asio::buffer_sequence_begin<add_rvalue_reference<_Ty>::type>(const ConstBuffer &,enable_if<std::is_convertible<const add_rvalue_reference<_Ty>::type*,const boost::asio::const_buffer*>::value,void>::type *) noexcept'
3> with
3> [
3> _Ty=const unkNown-type &,3> ConstBuffer=add_rvalue_reference<const unkNown-type&>::type
3> ]
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/buffer.hpp(389): note: or 'const boost::asio::mutable_buffer *boost::asio::buffer_sequence_begin<add_rvalue_reference<_Ty>::type>(const MutableBuffer &,const boost::asio::mutable_buffer*>::value,3> MutableBuffer=add_rvalue_reference<const unkNown-type&>::type
3> ]
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/buffer_traits.hpp(123): note: while trying to match the argument list '(add_rvalue_reference<_Ty>::type)'
3> with
3> [
3> _Ty=const unkNown-type &
3> ]
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/impl/buffers_cat.hpp(127): note: see reference to alias template instantiation 'buffers_iterator_type<unkNown-type>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/http/chunk_encode.hpp(251): note: see reference to class template instantiation 'boost::beast::buffers_cat_view<boost::beast::http::detail::chunk_size,boost::asio::const_buffer,boost::beast::http::chunk_crlf>::const_iterator' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/relationship.hpp(474): note: see reference to class template instantiation 'boost::asio::execution::detail::relationship_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/outstanding_work.hpp(475): note: see reference to class template instantiation 'boost::asio::execution::detail::outstanding_work_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/occupancy.hpp(123): note: see reference to class template instantiation 'boost::asio::execution::detail::occupancy_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/mapping.hpp(604): note: see reference to class template instantiation 'boost::asio::execution::detail::mapping_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/context.hpp(130): note: see reference to class template instantiation 'boost::asio::execution::detail::context_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/bulk_guarantee.hpp(687): note: see reference to class template instantiation 'boost::asio::execution::detail::bulk_guarantee_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/blocking_adaptation.hpp(663): note: see reference to class template instantiation 'boost::asio::execution::detail::blocking_adaptation_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/blocking.hpp(836): note: see reference to class template instantiation 'boost::asio::execution::detail::blocking_t<0>' being compiled
3>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/impl/buffers_cat.hpp(127): error C3546: '...': there are no parameter packs available to expand
3>Done building project "lib-beast.vcxproj" -- Failed.
4>------ Rebuild All started: Project: websocket-server-sync,Configuration: Debug x64 ------
4>Building Custom Rule C:/drive_d/programming/projects/cpp/3rdparty/boost_1_75_0/libs/beast/example/websocket/server/sync/CMakeLists.txt
4>websocket_server_sync.cpp
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/buffer_traits.hpp(123): error C2668: 'boost::asio::buffer_sequence_begin': ambiguous call to overloaded function
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/buffer.hpp(399): note: Could be 'const boost::asio::const_buffer *boost::asio::buffer_sequence_begin<add_rvalue_reference<_Ty>::type>(const ConstBuffer &,void>::type *) noexcept'
4> with
4> [
4> _Ty=const unkNown-type &,4> ConstBuffer=add_rvalue_reference<const unkNown-type&>::type
4> ]
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/buffer.hpp(389): note: or 'const boost::asio::mutable_buffer *boost::asio::buffer_sequence_begin<add_rvalue_reference<_Ty>::type>(const MutableBuffer &,4> MutableBuffer=add_rvalue_reference<const unkNown-type&>::type
4> ]
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/buffer_traits.hpp(123): note: while trying to match the argument list '(add_rvalue_reference<_Ty>::type)'
4> with
4> [
4> _Ty=const unkNown-type &
4> ]
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/impl/buffers_cat.hpp(127): note: see reference to alias template instantiation 'buffers_iterator_type<unkNown-type>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/http/chunk_encode.hpp(251): note: see reference to class template instantiation 'boost::beast::buffers_cat_view<boost::beast::http::detail::chunk_size,boost::beast::http::chunk_crlf>::const_iterator' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/relationship.hpp(474): note: see reference to class template instantiation 'boost::asio::execution::detail::relationship_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/outstanding_work.hpp(475): note: see reference to class template instantiation 'boost::asio::execution::detail::outstanding_work_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/occupancy.hpp(123): note: see reference to class template instantiation 'boost::asio::execution::detail::occupancy_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/mapping.hpp(604): note: see reference to class template instantiation 'boost::asio::execution::detail::mapping_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/context.hpp(130): note: see reference to class template instantiation 'boost::asio::execution::detail::context_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/bulk_guarantee.hpp(687): note: see reference to class template instantiation 'boost::asio::execution::detail::bulk_guarantee_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/blocking_adaptation.hpp(663): note: see reference to class template instantiation 'boost::asio::execution::detail::blocking_adaptation_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/asio/execution/blocking.hpp(836): note: see reference to class template instantiation 'boost::asio::execution::detail::blocking_t<0>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/core/impl/buffers_cat.hpp(127): error C3546: '...': there are no parameter packs available to expand
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/http/parser.hpp(56): error C2338: BodyReader type requirements not met
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/websocket/impl/handshake.hpp(48): note: see reference to class template instantiation 'boost::beast::http::parser<false,boost::beast::http::basic_string_body<char,std::char_traits<char>,std::allocator<char>>,std::allocator<char>>' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/websocket/impl/handshake.hpp(56): note: see reference to class template instantiation 'boost::beast::websocket::stream<NextLayer,deflateSupported>::handshake_op<Handler>::data' being compiled
4>C:\drive_d\programming\projects\cpp\3rdparty\boost_1_75_0\boost/beast/websocket/impl/handshake.hpp(185): note: see reference to class template instantiation 'boost::beast::websocket::stream<NextLayer,deflateSupported>::handshake_op<Handler>' being compiled
4>Done building project "websocket-server-sync.vcxproj" -- Failed.
========== Rebuild All: 2 succeeded,2 Failed,0 skipped ==========
有人能告诉我这里发生了什么或者我做错了什么吗?
解决方法
我也在 Boost Beast 项目的 Github 页面上发布了这个问题,我从一位维护者那里得到了一个答案,即由于旧版本的 MSVS 2017 本身存在错误,因此很难编译 Boost Beast 示例项目(请参阅 link 来回答我的问题)。结论是最好使用更可靠的 MSVS 2019 并在那里编译。
我也试过用 MSVS 2019 编译它,它可以工作。
如果您无法更改 MSVS 版本,那么您应该联系维护人员以帮助您解决问题。对我来说,我的 MSVS 2017 版本(不是最新的 MSVS 2017 版本)在编译 Beast 时出现问题的信息已经足够好了。
更新:
关于使用 MSVS 2017 构建 Boost Beast 是使用最新版本的 MSVS 2017 它应该可以工作(链接 here)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。