views:

104

answers:

2
+1  Q: 

Cross Platform C?

+5  A: 

An executable has a specific format (e.g. ELF) and architecture (e.g. x86). Thus, you do have to compile multiple times. However, it is possible to cross-compile to e.g. Windows 7 x86 and Mac OS X x86 from Ubuntu. The procedures for each are different, as you would expect.

For Windows, you will want mingw32. See Compile Windows C console applications in Linux .

For OS X, see How to compile Intel Mac binaries on Linux? , which links to a tutorial.

You can search to find more information on each.

Matthew Flaschen
For the OS X tutorial, it seems kind of old. Will it also work for the iPhone SDK?
Mohit Deshpande
You can use [Cygwin](http://cygwin.org/) as an alternative to MingW32.
Jonathan Leffler
@Mohit, I don't know, you asked about a MacBook. For Linux->iPhone, see [Starting iPhone app development in Linux?](http://stackoverflow.com/questions/276907/starting-iphone-app-development-in-linux); it's certainly not simple, though.
Matthew Flaschen
+1  A: 

Unfortunately, the executable file formats used by Linux, Windows, and OSX are profoundly different in detail. There is no way to produce a single binary that works on all three.

It is possible to generate Windows and OSX executables using cross compilers from Linux (or vice versa in any other combination you like) but setting up the build environment is probably more trouble than it's worth. See http://www.kegel.com/crosstool/ if you really want to try that.

Zack
Check the update, I don't mean to create a SINGLE binary to run on multiple platforms.
Mohit Deshpande