I've seen several tutorials on how to compile C++ applications for Windows on a linux system, however, I have failed to find a way to use Windows specific headers (i.e Windows.h) in my C++ program to compile for Windows (.exe/.dll). I was wondering if anyone knew how I can compile Visual C++ programs on Linux that use Windows OS Specific headers/functions (just compile). Thanks!
Asked
Active
Viewed 990 times
0
-
If all you want to do is compile there shouldn't be much of a problem. What do you mean you failed to find a way? What have you tried and what were the results? And better yet, why would you want to compile only? That accomplishes precisely nothing. – Carey Gregory Dec 17 '17 at 23:00
-
Pretty sure this already has an answer: https://stackoverflow.com/questions/2033997/how-to-compile-for-windows-on-linux-with-gcc-g – Joseph Willcoxson Dec 18 '17 at 03:44
-
Hi Joe, which answer works for you? I tried using "sudo apt-get install mingw-w64", however, when I try to use "Windows.h" in my code, it says it cannot find it. – Dec 18 '17 at 04:47
1 Answers
0
You can't. Windows system headers, e.g. windows.h
reference OS specific APIs that are not known to Linux. Only Microsoft's compiler can create Windows format objects and executables and it doesn't run on Linux.
You can create cross-platform applications consisting of common code that will build and run on Windows and Linux. But the only way to use platform specific APIs in such an application, e.g. GUI, is to #define
sections in/out according to the build environment.

stanthomas
- 1,141
- 10
- 9
-
-
Not true that only Microsoft's compiler can create Windows format objects and executables. GNU C/C++ compiler can create Windows executables on Windows.So can Intel's compiler. Whoever Borland got sold to, I'm sure their C++ compiler can build Windows executables. – Joseph Willcoxson Dec 18 '17 at 03:43
-
First of all, you can create a Windows executable on Linux, again, if I was making an application for both Windows AND Linux, I'd design it for both operating systems, however, I just want to make a build server to build my Windows applications. This doesn't really answer my question, and I've seen it done before in a very hacky way. I was looking to see if there was anyone that already documented the process of doing so. – Dec 18 '17 at 04:33
-
Ok, I'll stand corrected. A quick Google of "gcc windows executable" threw up this: https://stackoverflow.com/questions/38786014/how-to-compile-executable-for-windows-with-gcc-with-linux-subsystem , does that answer your question? – stanthomas Dec 19 '17 at 00:05
-
@Joe Willcoxson - true, there were a whole bunch of C/C++ compilers for Windpws back in the day, anyone remember Metaware High-C? I used Visual C++ as a placeholder but yes, Borland C++ is still kicking around in an offering from Embarcadero. It only builds Windows executables on Windows though. Seems that MinGW has a cross-compilation capability; I wasn't aware of this and have no idea how useful it is. – stanthomas Dec 19 '17 at 00:22