I am making a program in Linux that is designed to run in Windows. I had only started programming on Linux earlier this day. I am using the default g++ compiler. When I try to compile my program, I get an error:
1 2
free_roam.cpp:7:21: fatal error: Windows.h: No such file or directory
compilation terminated.
Can I simply download Windows.h? Is there is a package I didn't install? Is there no possible way for me to get Windows.h?
If you're wondering, I cannot simply use another header, as very much of my code uses that header, and (as far as I know) there is no alternative.
Cross-compiling from linux, especially if you're using a debian based distribution like Ubuntu, is a piece of cake! You just need to install minGW first... sudo apt-get install mingw32
Then write code like you normally would, using standard libraries only (iostream, vector, string, cstdio/lib, etc.) Compiling on linux is the same as it always is: g++ -s -o output main.cpp
and then to produce a Windows executable... i586-mingw32msvc-g++ -s -o output.exe main.cpp
Don't worry about trying to remember the minGW compiler's long name. Typing i5, then hitting tab, and then typing g++ will fill it out for you. Remember that only the standard libraries are portable. If you try to build something using unistd.h, or if you wanted to functionality only available from windows.h, you're out of luck.
Note that executables produced by minGW will be fairly large (about half a megabyte if you use the -s flag). This is because all of the libraries that might be dynamically linked when built with g++ or in visual studio, are built into the executable. This means that the .exe minGW builds will run on all Windows systems without other dependencies, where executables built by visual studio typically don't work correctly without installing a run time on the client's system.
Wow. I'm...really surprised I didn't know that. Just tried it now, and I can definitely include windows.h and compile with minGW in linux. Test window application works exactly as expected.
EDIT: Programs built this way spawn a console window when they launch. I don't know if it can be suppressed, but a program as trivial as
1 2 3 4 5 6
#include <windows.h>
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmd, int show){
MessageBox(NULL, "test message","Test",MB_OK);
return 0;
}