I am trying to move away from using Visual Studio and use command-line compilation more, however I am having an issue with a project that uses ASIO in its header-only, standalone (non-boost) form compiled using Clang on Windows.
Both Visual Studio and Clang compile without errors, however when running the Clang version, I get a runtime error of thread: The attempted operation is not supported for the type of object referenced.
when creating a asio::thread
A minimal example;
main.cpp
#include <iostream>
#include <vector>
#include <string>
#include <map>
#define _WIN32_WINNT 0x0601
#define ASIO_STANDALONE
#define STANDALONE
#include <asio.hpp>
void _stuff()
{
std::cout << "B" << std::endl;
}
int main()
{
asio::io_context ctx;
std::cout << "A ";
try
{
asio::thread thr(std::bind(&_stuff));
thr.join();
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
}
}
Clang build command
clang++ -std=c++20 main.cpp -I"asio-1.30.2/include" -luser32 -lkernel32 -lshell32
-> 0
Visual Studio is configured as ‘standard’ for a blank C++ application with the exception of asio/include
being added to the include path. Visual Studio also builds without issue.
The version built through Visual Studio works as expected outputting A B
however the Clang version outputs
A
thread: The attempted operation is not supported for the type of object referenced.
I have three possible guesses;
- I have not configured ASIO correctly via the
#define
‘s - I have not linked the program properly
- ASIO does not support building header-only, standalone, on windows using clang