开发者

Binary file from one linux to another

开发者 https://www.devze.com 2023-03-11 14:28 出处:网络
Is there any possible way to run binary compiled on another Linux? I know that of course the easiest is to rebuild that on another machine but lets assume that the only thing we can get is a binary fi

Is there any possible way to run binary compiled on another Linux? I know that of course the easiest is to rebuild that on another machine but lets assume that the only thing we can get is a binary file, so is it possible or not? (I know that pro开发者_如何转开发bably it wont be easy but I'm just curious).


It is generally possible, given the same or similar libraries used in the binary. Every so often you have different versions of libraries on different versions of Linux and you'll end up with a crash, but very often you can run ldd to see which libraries the executable uses and then check on the second platform to see if those libraries are also present.


While the shared library matching thing is very true (use ldd to get the list of shared libraries which need to be identical) more generally, the system need to be the same architecture (or have compatibility libraries/kernels installed for x86 binaries running on x86_64 architectures).

One option is to statically link (or provide your own shared libraries) so that you only need compatibility at the kernel ABI level. Of course, this means that systems/distributions using non-standard options (NIS, LDAP, etc) are kinda messed up.

Another option is to distribute .a files and perform the final linking on the target system. This of course assumes that the system has a compiler, but is probably the most portable for an object distribution.

However, in all cases you must have architecture compatibility. x86 is the lowest common denominator, but is by no means the only one.


If the libc versions are the same and any other dependent shared libraries are available, then yes, you can run binaries from other Linuxes. Use 'ldd -v' on the binary on the target platform to see if any libraries are missing.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号