Boost Asio:'...':没有可扩展的参数包

问题描述 投票:0回答:1

我正在尝试使用 boost asio 发送一些 udp 数据包,但我得到:

[main] Building folder: C:/Users/tom.mclean/src/Nemo/build nemo
[build] Starting build
[proc] Executing command: C:\Users\tom.mclean\AppData\Local\miniconda3\Scripts\cmake.EXE --build C:/Users/tom.mclean/src/Nemo/build --parallel 18 --target nemo --
[build] [0/2] Re-checking globbed directories...
[build] [1/3] Building CXX object CMakeFiles\nemo.dir\nemo\nemo.cpp.obj
[build] FAILED: CMakeFiles/nemo.dir/nemo/nemo.cpp.obj 
[build] C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1436~1.325\bin\Hostx86\x86\cl.exe  /nologo /TP -DBOOST_CONTAINER_DYN_LINK -DBOOST_CONTAINER_NO_LIB -DBOOST_CONTEXT_DYN_LINK="" -DBOOST_CONTEXT_EXPORT=EXPORT -DBOOST_CONTEXT_NO_LIB="" -DBOOST_COROUTINES_DYN_LINK -DBOOST_COROUTINE_DYN_LINK -DBOOST_COROUTINE_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_DATE_TIME_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK=1 -DBOOST_FILESYSTEM_NO_LIB -DBOOST_UUID_FORCE_AUTO_LINK -DEZXML_NOMMAP -DFMI4C_STATIC -DHAVE_MEMMOVE=1 -DUSE_FILE32API -IC:\Users\tom.mclean\src\Nemo\external\ODSClient\include -IC:\Users\tom.mclean\src\Nemo\external\fmi4c\include -IC:\Users\tom.mclean\src\Nemo\external\fmi4c\3rdparty -IC:\Users\tom.mclean\src\Nemo\external\fmi4c\3rdparty\minizip -external:IC:\Users\tom.mclean\src\Nemo -external:IC:\Users\tom.mclean\src\vcpkg_installed\x86-windows\include -external:IC:\Users\tom.mclean\src\vcpkg_installed\x86-windows\include\eigen3 -external:IC:\Users\tom.mclean\src\vcpkg_installed\x86-windows\include\SDL2 -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /O2 /Ob2 /DNDEBUG -std:c++20 -MD /bigobj /showIncludes /FoCMakeFiles\nemo.dir\nemo\nemo.cpp.obj /FdCMakeFiles\nemo.dir\nemo.pdb /FS -c C:\Users\tom.mclean\src\Nemo\nemo\nemo.cpp
[build] Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
[build] - add -D_WIN32_WINNT=0x0601 to the compiler command line; or
[build] - add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.
[build] Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
[build] C:\Users\tom.mclean\src\vcpkg_installed\x86-windows\include\boost/asio/co_composed.hpp(162): error C3546: '...': there are no parameter packs available to expand
[build] C:\Users\tom.mclean\src\vcpkg_installed\x86-windows\include\boost/asio/co_composed.hpp(163): note: see reference to class template instantiation 'boost::asio::detail::co_composed_state_return<Executors,Handler,boost::asio::detail::co_composed_returns<Signatures...>>' being compiled
[build] ninja: build stopped: subcommand failed.
[proc] The command: C:\Users\tom.mclean\AppData\Local\miniconda3\Scripts\cmake.EXE --build C:/Users/tom.mclean/src/Nemo/build --parallel 18 --target nemo -- exited with code: 1
[driver] Build completed: 00:00:08.065
[build] Build finished with exit code 1

我的最小例子是:

#include <boost/asio.hpp>
#include <iostream>

int main() {
    try {
        boost::asio::io_context io_context;
        boost::asio::ip::udp::endpoint server_endpoint(boost::asio::ip::make_address("127.0.0.1"), 12345);
        boost::asio::ip::udp::socket socket(io_context);
        socket.open(boost::asio::ip::udp::v4());
        const std::string message = "Hello, UDP Server!";
        socket.send_to(boost::asio::buffer(message), server_endpoint);
        std::cout << "Message sent to server: " << message << std::endl;

    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
    }

    return 0;
}

我的 CMakeLists.txt 是:

cmake_minimum_required(VERSION 3.18)
set(BOOST_ALL_STATIC_LIB ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)

project(test VERSION 1.0.0 LANGUAGES CXX)
find_package(boost_asio CONFIG REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE Boost::asio)
target_compile_features(main PUBLIC cxx_std_20)

错误似乎来自

target_compile_features(main PUBLIC cxx_std_20)
。如果我将其设置为
target_compile_features(main PUBLIC cxx_std_17)
它编译得很好。我认为 C++ 是向后兼容的,那么为什么会出现这种情况呢?

错误的 Github 存储库:https://github.com/mcleantom/so-79276056

c++ boost boost-asio
1个回答
0
投票

感谢 Github 存储库中优秀的独立示例。

因此,我清理了 Windows 安装,安装了 VS2022、CMake、vcpkg、Ninja 和 Github Desktop 来重现此情况。

事实证明它无法为我重现。这是我应用更新到 17.12.3 之前和之后

Microsoft Visual Studio Community 2022
Version 17.12.3
VisualStudio.17.Release/17.12.3+35527.113
Installed Version: Community
Visual C++ 2022   00482-90000-00000-AA007
Microsoft Visual C++ 2022
© www.soinside.com 2019 - 2024. All rights reserved.