带Rust的便携式二进制文件 [英] Portable binaries with Rust

查看:105
本文介绍了带Rust的便携式二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构建带有rust的可移植可执行文件时遇到问题.

I have problems building a portable executable with rust.

在Ubuntu上运行仅使用 cargo build 构建的可执行文件失败

Running an executable simply built with cargo build on Ubuntu fails with

./test: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by ./test)

使用 rustc ... -C link-args = -static 进行的构建无法正确链接( ld ./test 的输出):

Building with rustc ... -C link-args=-static fails to link correctly (output of ld ./test):

ld: error in ./test(.eh_frame); no .eh_frame_hdr table will be created.

除了在具有旧glibc版本的旧系统上构建之外,是否有其他方法可以解决此问题?

Is there a way around this except building on an older system with an old glibc version?

推荐答案

Glibc不是静态链接的(就像我们可能想要的那样,它竭尽全力防止这种情况的发生).结果,系统库(libstd等)始终依赖于构建它们的glibc版本.这就是为什么mozilla使用的linux集群中的构建机器人是centos的旧版本.

Glibc is not linked statically (much as we might have liked to, it goes out of its way to prevent this). As a result, the system libraries (libstd and such) are always dependent on the glibc version on which they were built. This is why the buildbots in the linux cluster mozilla uses are/were old versions of centos.

请参见 https://github.com/rust-lang/rust/issues/9545 https://github.com/rust-lang/rust/issues/7283

不幸的是,目前,我相信除了确保您在具有比要部署的glibc更旧的系统上构建之外,没有其他解决方法.

Unfortunately at this time I believe there is no workaround aside from making sure you build on a system with an older glibc than you're going to deploy to.

这篇关于带Rust的便携式二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆