0

I'm using a mac OS X 10.8.4 64 bit. I want to build some C/C++ programs on my mac, and then show them to some people who use windows. I can successfully compile it into an exe, using

g++ test.cpp -o test.exe on the terminal

But when run in my PC, that exe file raises this error: "This verison of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) verion of the program." Note: My PC is also 64 bits

2
  • 2
    If you're running that command on OS X, all you did is give the file name a ".exe" ending. You need to actually compile it for windows, which would require you to set up cross-compiling on OS X or set up a compiler on Windows.
    – Cornstalks
    Feb 22, 2014 at 0:21
  • The easiest way is probably to install Windows on a VM (use VirtualBox, or, VMware Fusion, or ...) and grab a copy of Visual Studio Express.
    – mpontillo
    Feb 22, 2014 at 0:40

1 Answer 1

2

Using g++ test.cpp -o test.exe does not produce a Windows EXE executable, it just produces a Mac OS X executable that happens to have the .exe extension on its filename. To produce Windows EXE executables you need to use a Windows compiler, such as Microsoft Visual Studio or gcc on cygwin.

4
  • Ok, thanks, but does that mean that there is no way of creating a C/C++ executable windows file from a mac?
    – Brobz
    Feb 22, 2014 at 0:44
  • 1
    Yes, there is. You will nave to cross compile using, for instance, MinGW. Feb 22, 2014 at 0:47
  • 2
    No, it's possible, but it is WAY more involved than you probably want to get into. It requires cross-compiling (compiling something with a separate build and target environment). This is relatively common for trickier targets like embedded platforms, but between Mac OS X and Windows it's either never or almost never done. At least I've never heard of anyone doing it.
    – jeremycole
    Feb 22, 2014 at 0:48
  • Cross-compiling for desktop isn't heard of. It doesn't actually get you out of having to have e.g. a Windows machine (since you need to test), but it allows you to have just one build machine. Feb 22, 2014 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.