我正在尝试使用 Rust 创建一个静态可执行文件。我是not尝试静态链接特定库,我试图创建一个可执行文件根本不使用动态链接。我有以下(否则有效)测试:
$ cat hello.rs
fn main()
{
print!("Hello, world!\n");
}
$ rustc hello.rs -o hello
$ file hello
hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, [etc]
请注意dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2
。静态可执行文件有statically linked
反而。 (就我而言corrupted section header size
,尽管如果我能说服 Rust 复制,我会感到惊喜that.)
我需要传递哪些选项rustc
让它生成一个实际的静态可执行文件(具体来说:一个甚至file
同意是静态链接)。
自 Rust 1.19 起,您可以静态链接 C 运行时 (CRT) 以避免 Windows 上这种非常常见的情况:
该程序无法启动,因为您的系统中缺少 VCRUNTIME140.dll
电脑。尝试重新安装该程序来解决此问题。
将其添加到您的.cargo/config
文件,使用适合您平台的目标三元组:
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
编辑的替代方法.cargo/config
是要通过-C target-feature=+crt-static
手动 rustc。
也可以看看:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)