Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create binaries for other platform on Linux?

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 ?

like image 966
Xinus Avatar asked Jan 24 '23 00:01

Xinus


1 Answers

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

like image 119
Rob Vermeulen Avatar answered Jan 28 '23 14:01

Rob Vermeulen