views:

109

answers:

3

Is there a way to take my C++ code and cross compile it to run on Windows, Mac OS, and Linux? Is there a tool to do this, or does it have to be manually compiled on each OS via Terminal/Cygwin?

+2  A: 

You can cross compile with what is known as a cross-compiler. Mingw can be installed as such. I believe MacOS just uses g++ so you can probably make a cross compiler for it as well. Never done it myself. You can scour the web for directions. Here's the top link I got from google:

http://linux.bytesex.org/cross-compiler.html

Noah Roberts
MacOS does use a variant of g++, but there are a lot of subtle differences in the toolchain, throw in universal binary support and things could get ugly. This doesn't mean its not possible to target MacOS from another platform, but it could be a real headache.
mikerobi
+2  A: 

The easiest way is to use a Mac OS X machine with VMs for Linux and Windows (using e.g. Parallels or VMware Fusion). You can put the source code in a directory which is shared with the VMs and then use the native tools for each OS to compile it.

Paul R
A: 

You should go through your code and convert as much as you can to ANSI C++. Factor remaining platform dependent code into separate modules. These modules may need to be rewritten for other platforms, and let the build tool select the appropriate modules. The remaining code should compile with few problems on the other platforms.

Also, verify that your GUI, if you are using one, is cross-platform compatible. Otherwise it will be a mess to convert to the other platforms.

Thomas Matthews