Tuesday 1 August 2017

How to port Linux executables from one system onto another?

There are many Linux distributions, e.g., Ubuntu, Redhat, CentOS, Debian, etc. Even for the same distribution, there are many versions. We often want to port a compiled executable from one system directly onto another system without re-compiling, because compilation is very tedious and time consuming.

Firstly, we need to collect all dependent dynamic libraries, use the following command:


 ldd -v <executable>

Secondly, copy your target executable (we call it <exec>) together with all dependency libraries (those *.so files after "=>") into a folder (we call it <exec-lib>), and then copy the folder onto another machine.

Lastly, you can run your target executable on the new system in the following way. Out of all your copied libraries, there is one called ld-linux*.so.* (we call it ld.so). This is the main library loader, it is used in the following way:
 ld.so --library-path <exec-lib>  <exec>

In this way, you can get rid of the notorious "GLIBC_XXX not found" error. However, if you encounter the error "FATAL: kernel too old", that means your program has used certain new features in the newer system, and then you do have to re-compile in a system with old-version kernel.