I’m trying to use boost asio to send some udp packets, but I am getting:
[main] Building folder: C:/Users/tom.mclean/src/Nemo/build nemo
[build] Starting build
[proc] Executing command: C:Userstom.mcleanAppDataLocalminiconda3Scriptscmake.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 CMakeFilesnemo.dirnemonemo.cpp.obj
[build] FAILED: CMakeFiles/nemo.dir/nemo/nemo.cpp.obj
[build] C:PROGRA~1MIB055~12022COMMUN~1VCToolsMSVC1436~1.325binHostx86x86cl.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:Userstom.mcleansrcNemoexternalODSClientinclude -IC:Userstom.mcleansrcNemoexternalfmi4cinclude -IC:Userstom.mcleansrcNemoexternalfmi4c3rdparty -IC:Userstom.mcleansrcNemoexternalfmi4c3rdpartyminizip -external:IC:Userstom.mcleansrcNemo -external:IC:Userstom.mcleansrcvcpkg_installedx86-windowsinclude -external:IC:Userstom.mcleansrcvcpkg_installedx86-windowsincludeeigen3 -external:IC:Userstom.mcleansrcvcpkg_installedx86-windowsincludeSDL2 -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /O2 /Ob2 /DNDEBUG -std:c++20 -MD /bigobj /showIncludes /FoCMakeFilesnemo.dirnemonemo.cpp.obj /FdCMakeFilesnemo.dirnemo.pdb /FS -c C:Userstom.mcleansrcNemonemonemo.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:Userstom.mcleansrcvcpkg_installedx86-windowsincludeboost/asio/co_composed.hpp(162): error C3546: '...': there are no parameter packs available to expand
[build] C:Userstom.mcleansrcvcpkg_installedx86-windowsincludeboost/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:Userstom.mcleanAppDataLocalminiconda3Scriptscmake.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
My minimal example is:
#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;
}
And my CMakeLists.txt is:
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)
The error seems to come from target_compile_features(main PUBLIC cxx_std_20)
. If I set it to target_compile_features(main PUBLIC cxx_std_17)
it compiles fine. I thought C++ was backwards compatible, so why does this break?
Github repo of error: https://github.com/mcleantom/so-79276056
18
Kudos for the excellent self-contained example in the Github repo.
So, I dusted off my Windows installation, installed VS2022, CMake, vcpkg, Ninja and Github Desktop to reproduce this.
It turns out it doesn’t reproduce for me. This is both before and after I applied the updates to 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
1