I created programs transferring information between client and server by C++ TCP socket programming and compile and run it on Linux. But how to compile the source code to windows executable for Windows user clients?
I've tried using
x86_64-w64-mingw32-g++ ...
to compile. But the it fails for not find these files.
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
I know Microsoft provides windows programming APIs, but it will require a lot of adjustment of codes. How to correctly set a cross-compiler to compile it properly for Windows, without having to modify codes?
In theory, C++/C should be a high level language and is not platform-specific.
The solution here doesn't work for me (codes containing TCP sockets). How to compile C code in Linux to run on Windows?
#ifdef WIN32/#else/#endifblocks to conditionally use winsock instead of POSIX headers and apis...#ifdef _WIN32s to your code (notWIN32, btw), or to use a wrapper library that does it for you. There's also Cygwin, that might be able to compile your code as is, but A - I don't know if it's possible to cross-compile with it, and B - I'd argue that it shouldn't be a development target of new cross-platform software, but only a way of porting old non-portable software from Linux.