I'm new C++ and I'm trying to develop a very simple webserver app for Windows, but I'm compiling it on Ubuntu 22.04 using MinGW. All the versions of everything are the ones Ubuntu 22.04 will give to me with the latest updates from its default repositories.
I can compile it perfectly fine on Ubuntu: g++ -std=c++17 -o main main.cpp -lcrypto -lpthread -I./Crow/include -I./json/include -I./tinyfiledialogs ./tinyfiledialogs/tinyfiledialogs.c -I./asio/include
However, if I try to compile it targeting Windows with x86_64-w64-mingw32-g++ -std=c++17 -o main.exe main.cpp -lws2_32 -static-libgcc -static-libstdc++ -lcrypto -lpthread -I./Crow/include -I./json/include -I./tinyfiledialogs ./tinyfiledialogs/tinyfiledialogs.c -I./asio/include
I get a million errors that all look like this:
In file included from ./Crow/include/crow.h:15,
from main.cpp:13:
./Crow/include/crow/websocket.h: In destructor ‘crow::websocket::Connection<Adaptor, Handler>::~Connection()’:
./Crow/include/crow/websocket.h:132:26: error: ‘std::this_thread’ has not been declared
132 | std::this_thread::yield();
| ^~~~~~~~~~~
In file included from ./Crow/include/crow.h:24,
from main.cpp:13:
./Crow/include/crow/http_server.h: At global scope:
./Crow/include/crow/http_server.h:268:14: error: ‘condition_variable’ in namespace ‘std’ does not name a type
268 | std::condition_variable cv_started_;
| ^~~~~~~~~~~~~~~~~~
In file included from ./Crow/include/crow.h:24,
from main.cpp:13:
./Crow/include/crow/http_server.h:21:1: note: ‘std::condition_variable’ is defined in header ‘<condition_variable>’; did you forget to ‘#include <condition_variable>’?
20 | #include "crow/version.h"
+++ |+#include <condition_variable>
21 | #include "crow/http_connection.h"
In file included from ./Crow/include/crow.h:24,
from main.cpp:13:
./Crow/include/crow/http_server.h:269:14: error: ‘mutex’ in namespace ‘std’ does not name a type
269 | std::mutex start_mutex_;
ChatGPT is insistent that the error is because the #include is missing from various files, but that is not true. I opened the files and the #include lines are indeed there.
I had exactly the same issue replacing Crow with httplib instead. I've also tried changing c++17
to 11 or emitting it entirely - no difference.
How can I compile my very simple app targeting Windows?
Minimal reproducible example:
#include <crow.h>
int main() {
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([]() {
return "Hello, World!";
});
app.port(8080).multithreaded().run();
}
The issue was caused by using x86_64-w64-mingw32-g++
when it should instead be x86_64-w64-mingw32-g++-posix
.