views:

410

answers:

7

Any way to make a binary in a Linux distribution and run it on another distribution with same architecture? Or I should compile and build it on different distributions?

Is there any compatibility between Redhat, Debain based distributions for binary files? (I want to use my ubuntu binary file on fedora!)

+2  A: 

Normally it's ok to use binaries across linux distributions as long as you have the same set of libraries available. You can use 'ldd' to check which libraries are needed by a binary. libc should sure have the same version in the distributions involved.

+2  A: 

It works. But it also depends on the version of the shared libraries you use, including libc, libstdc++ which are forced by the compiler version that may differ from distro to distro.

Didier Trosset
+3  A: 

You could statically link your executables for portability.

Richard Pennington
No he can't. When do people get it that statically linked executables are not supported anymore. Read the LSB.
Lothar
+2  A: 

Statically linking your binaries makes them LESS portable because some libraries won't then work correctly for that machine (differing authentication methods, etc).

If you statically link any "unusual" libraries and keep your set of supported distros to a minimum, you should be ok.

Don't statically link the C library (or the whole binary), that's a recipe for trouble :)

Look at what (e.g.) Google do with Chrome.

MarkR
Well, that's not quite true, depending on the program. I have successfully delivered statically linked binaries many times. Think of a compiler: it reads a file does stuff and writes a file. What makes you think that that can't be statically linked?
Richard Pennington
You can statically link your binaries, but they can't then benefit from updates to the C library, nor be compatible with other changes that distributions or end-user administrators may have made e.g. custom nss libraries.
MarkR
+3  A: 

What language is your application coded in? If its in a language like Python, (and no C bindings) or Java or any other VM based language, then I think you can trust the VM to make sure your application will work on the different Linux distributions.

Also, there is the Linux Standard Base which you can refer to.

HTH,Amit

Amit
+4  A: 

Enter Linux Standard Base to reduce the differences between individual Linux distributions. See

dtmilano
+1  A: 

The best way is to distribute the source code and to make it easy to build the source on any reasonable Linux distribution. This is better than binary distribution because it is not enough to make the binary compatible with shared libraries. You also need to make sure you adapt your program to things like distribution specified locations and conventions for where web apps go, or how e-mail is sent, or how services are started, or how to determine the default paper size, or a myriad of other details.

See for example the Debian Policy Manual for a document describing many of the things a distribution needs to decide to ensure compatibility between applications running on it. You don't need to read it through or learn it by heart, but it shows the scope of the issues that may trip you.

You should probably work together with several of the major distributions to ensure your application works well with all of them. Most distributions' developers will happily help if you approach them politely. If you're lucky, you can attract volunteers from the distros to make the binary packaging for you, and that will quickly give you feedback on what you need to change at the source level to make your application easy to package.

The Linux Standard Base already mentioned by others attempts to work out a cross-distribution solution to these variables, but it is not comprehensive and not fully supported by most distributions. However, most distributions consider it a problem if they accidentally break LSB compatibility.

Lars Wirzenius