English 中文(简体)
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 ?

最佳回答

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

问题回答

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.

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.

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

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)!

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.

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





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签