views:

355

answers:

7

Is it possible to create binaries of other platform on Linux? Say I have a program that can be compiled using gcc to .o file but can we use it to output exe that can be run on windows ?

A: 

Google for "linux cross compilation windows". The first link looks pretty good.

Aaron Digulla
Note that the build system is pretty important. The examples there are using the configure script built by the common autoconf pipeline. Hopefully your project is already using something like this.
Jefromi
+1  A: 

Yes. Look for the cross-compiler of the target platform.

This is how you develop mobile application for ARM processors and other embeeded platforms. Ex: When you write a symbian application you can run on windows simulator during development but when you deploy it you need to compile the project using ARM cross-compiler because almost all phones run on ARM processors.

this. __curious_geek
A: 

I don't know that kind of tool, but principally I can't see any reason that makes that impossible.

For example there can be a tool on Linux which can compile C++ code by mapping to not Linux API function but to Win32 API functions (by knowing their addresses)!

Narek
+6  A: 

Short version: yes, you can. This is called cross-compiling and any search on google with this keyword will give you adequate results.

Now the reality: It takes quite the effort to have even a relatively small piece of c/c++ code running on both platforms. Differences in API's, user interfaces, calling conventions, alignments and much more are common practice. Fortunately there are a lot of cross-platform tools that can help you. Google for Qt, a cross-platform user interface library. Or use Boost when and where you can. You'll probably need to add numerous #ifdef __WINDOWS__ or #ifdef __UNIX__ (these statements might be incorrect) to specify separate lines of code for each platform.

So it is not a sinecure to code for both platforms and, depending on the complexity of the software you're writing, requires in-depth knowledge of operating systems in general and both OS'es in particular.

In other words: there's no tool that makes an .exe out of your .o, just like that.

Good luck!

~Rob

Rob Vermeulen
A: 

Neither of my ideas directly answer your question, however they are worth considering.

Running Windows on another machine (physical or virtual) is an option too. Having a full Windows environment would make debugging and testing the Windows version far easier.

Of course, you could use Java or a interpreted language (ie: python) and try to minimize platform specific code.

Steven
+1  A: 

Sure. If you have a compiler that can produce Windows binaries, it doesn't matter what system the compiler is running on.

A lot of Windows binaries for Unix-centric Open Source Projects are produced without anyone ever running Windows. E.g. Rake-Compiler is a project for building binary extensions for the MRI and YARV Ruby implementations. One of the main objectives of Rake-Compiler is that extension writers can publish extensions for Windows from Linux or OSX.

Jörg W Mittag
A: 

Try kdevelop and Qt if you need a GUI, you can 'definitely' build Windows GUI &/or console programs on a Linux host that way.

you could also try googling for "tool chains" and/or "cross compiling", I do the above to build software for my router (which is the 'other' platform - not Windows though) Basically the compile is accomplised by using a different compiler to compile for my target OS

queBurro
and 'why' the -1 here? educate me, tell me what's wrong with my post, cheers :)
queBurro