减少rust编译后程序体积

四 19 十一月 2026

编译release版本

cargo build --release

strip 命令

strip -s target/release/testGui

优化等级

通过修改默认优化等级方式减少体积,以cpu换空间,如果不是必要,建议不要改

在Cargo.toml中新增下面配置

[profile.release]
opt-level = 'z'

开启 LTO

减少体积,增加链接时间也是一个取舍问题

在Cargo.toml中新增下面配置

[profile.release]
lto = true

Category: 编程rust