I'm trying to write a HTTPS client connection to iOS and Android using C++11 Asio's header only library (without boost), and I'm testing the c++ code on Windows 10. (I tested on Windows 8 too, but the problem is the same)
I got an exception, so I write a simple example myself to find out what's happening. This is the code:
#include <iostream>
#include "asio.hpp"
void hello_world_thread() {
std::cout << "Hello world!" << std::endl;
}
int main()
{
asio::thread t(
std::bind(
&hello_world_thread
)
);
t.join();
return 0;
}
And if I run this inside / outside Code::Blocks I got the following exception:
terminate called after throwing an instance of 'std::system_error'
what(): thread: The attempted operation is not supported for the type of object referenced.This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
The build command is:
x86_64-w64-mingw32-g++.exe -std=c++11 -Wall -DASIO_STANDALONE -g -Iasio -c D:\Projektek\C++\AsioTeszt\main.cpp -o obj\Debug\main.o x86_64-w64-mingw32-g++.exe -o bin\Debug\AsioTeszt.exe obj\Debug\main.o -lws2_32 -static -static-libgcc -static-libstdc++ -m64
I had already tried the -pthread flag, but the error is the same.
MinGW version: gcc version 5.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project) Asio version: 1.10.6 (And tried with the Dev release too 1.11.0)
Finally I figured out after 3 days of suffering. The problem was with the MinGW installation, because I selected win32 at the Threads section. After reinstallation with posix threads selected everything works fine.
Edit: I again run into this problem but I used the Asio thread in another project. So I started remove everything until I had found out what was missing.
#include <map>
Without this it won't work.