rust - 无法释放文件。出现错误:无法编译“libc”
问题描述
我对这个语言和编码领域非常陌生。也是编码领域的初学者。我尝试构建和发布文件,但在编译 libc v0.2.62 时出错
error: Could not compile `libc`
pi@raspberrypi:~/Ganesh_Rust/Real_time/led_blink/src $ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.09s
Running `/home/pi/Ganesh_Rust/Real_time/led_blink/target/debug/led_blink`
pi@raspberrypi:~/Ganesh_Rust/Real_time/led_blink/src $ cargo build --release
Compiling libc v0.2.62
error: Could not compile `libc`.
Caused by:
process didn't exit successfully: `rustc --crate-name build_script_build /home/pi/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.62/build.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=b79e3ef31fa8c249 -C extra-filename=-b79e3ef31fa8c249 --out-dir /home/pi/Ganesh_Rust/Real_time/led_blink/target/release/build/libc-b79e3ef31fa8c249 -L dependency=/home/pi/Ganesh_Rust/Real_time/led_blink/target/release/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)
代码:我在 VS 代码中编写的这个程序,用于在树莓派 3 上闪烁 LED
use rust_gpiozero::*;
use std::thread;
use std::time::Duration;
fn main() {
//create a new LEd attached to pin 17 of raspberry pi
let led = LED::new(17);
//blink the led 5 times
for _ in 0.. 5{
led.on();
thread::sleep(Duration::from_secs(10));
led.off();
thread::sleep(Duration::from_secs(10));
}
}
cargo.toml 文件:
[package]
name = "led_blink"
version = "0.1.0"
authors = ["pi"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rust_gpiozero = "0.2.0"
我在 Raspberry pi 上得到输出,但可执行文件和二进制文件很大(5MB)。所以我想如果我发布也许我可以减小大小所以尝试使用 cargo build --release 命令发布,但得到这个错误。
解决方案
如果您使用的是 rustup 提供的二进制文件,那么这是一个已知问题 upstream。该问题有一个解决方法,即在中设置以下内容Cargo.toml
:
[profile.release]
codegen-units = 1
作为替代方案,您可以使用 Debianrustc
和cargo
软件包而不是 rustup,这应该可以正常工作。您可以从https://packages.debian.org/rustc和https://packages.debian.org/cargo下载软件包,也可以在其中添加适当的 APT 行/etc/sources.list
(参见https://deb.debian. org/例如)。请注意,Debian 并不总是有最新版本,但它们应该可以工作。
推荐阅读
- sql - 临时表解析 - SQL 错误 - 需要说明
- python - 当我尝试将使用 moviepy 创建的 .mp4 从 PC 导出到 iPhone 时,声音消失了
- java - 使用谓词的通用集合过滤
- r - 在 Shiny 中设置一个绘图缩放以匹配另一个绘图缩放
- sql - 来自函数的 SQL Server 默认列值
- rust - 如何将远程 crate 的枚举序列化和反序列化为数字?
- github - 交互式 Github Markdown 复选框(任务列表)
- android - 我应该在 Dagger2 和 Kotlin 中使用 @Singleton、object 还是两者都使用?
- python - 从具有不同行颜色的图像(OCR)中读取数字表
- arrays - 在 Swift 中,如何将 Data 分配给 UInt32 数组?