Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was trying to compile a php extension on Windows and ran into some trouble. I then thought it was possible to do the compilation for Windows on Linux, but turned out that wasn't possible.

Can someone explain to me why compiling has to be done on the same OS? I'm trying to understand this topic, specifically because if I want to distribute something, does that mean I have to compile it on all these OSs (Windows 7, Windows Vista, Windows XP, Linux, Mac, etc. etc. etc.) So what makes it not possible to compile for one OS on another? Is it the kernel or what?

share|improve this question

closed as off topic by Zoredache, Shane Madden, John Gardeniers, Ward, Mark Henderson Nov 8 '11 at 5:12

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

This might be a better fit over on – Zoredache Nov 8 '11 at 1:10
If you need/want to cross-compile you would be best off obtaining the proper tools to do the job. It's not something you can do with tools designed for a specific platform. – John Gardeniers Nov 8 '11 at 1:31
up vote 1 down vote accepted

As a general rule, it is much easier and more reliable to compile on the actual distribution on which it will be executed. There are often 'families' of distributions where you can get away with compiling on just one distribution in the family. Sometimes, families have tricks that enable you to minimize the number of compilations necessary.

You can generally make a single build for all modern versions of Windows. If you want to make a native 64-bit application, you'll need a second build. Generally, you can make this build on any version of Windows, but it's usually easiest to make it on the most current version you plan to support. (Windows is the exception. On other platforms, it is easiest to use the oldest version you plan to support.)

You can make a single build for all Linux platforms with at least Pentium 3 CPUs and kernels of version 2.6.0 or later. There are a few tricks to it, but it can be done.

You can make one build for all Intel Macs. Again, there are a few tricks to it, but it can be done.

Cross-compiling across OS families tends to be more trouble than it's worth. You need the native platform to test on anyway. For large deployments, one extra machine to build on is no problem. For small ones, use the test machine to build on -- you need it anyway.

The main exception is 'small' platforms that are intended for cross-compilation anyway. Small embedded systems, for example, may not even be capable of compiling on the native platform.

share|improve this answer

Cross-compilation is possible, but that doesn't mean that all software can be cross-compiled. Some software depends on libraries/components that only exist on the target platform. Some software depend on certain versions of development tools, for a successful build.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.