从一个linux到另一个linux的二进制文件
有没有可能的方法来运行在另一个Linux上编译的二进制文件?我知道当然最简单的方法是在另一台机器上重建它,但假设我们唯一可以获得的是二进制文件,那么这可能吗? (我知道这可能并不容易,但我只是很好奇)。
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 probably it wont be easy but I'm just curious).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果二进制文件中使用相同或相似的库,这通常是可能的。有时,您在不同版本的 Linux 上有不同版本的库,最终会崩溃,但通常您可以运行 ldd 来查看可执行文件使用哪些库,然后检查第二个平台,看看这些库是否也存在。
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.虽然共享库匹配的事情是非常正确的(使用 ldd 来获取需要相同的共享库的列表),但更普遍的是,系统需要具有相同的体系结构(或具有兼容性库/内核)为在 x86_64 架构上运行的 x86 二进制文件安装)。
一种选择是静态链接(或提供您自己的共享库),以便您只需要内核 ABI 级别的兼容性。当然,这意味着使用非标准选项(NIS、LDAP 等)的系统/发行版有点混乱。
另一种选择是分发 .a 文件并在目标系统上执行最终链接。当然,这假设系统有一个编译器,但对于对象分发来说可能是最可移植的。
但是,在所有情况下,您都必须具有体系结构兼容性。 x86 是最低公分母,但绝不是唯一的公分母。
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.
如果 libc 版本相同并且任何其他依赖共享库可用,那么是的,您可以从其他 Linux 运行二进制文件。在目标平台上的二进制文件上使用“ldd -v”来查看是否缺少任何库。
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.