无法释放文件。收到错误:无法'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));
}
}  

货物.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"

我在树莓派上获得输出,但可执行文件和二进制文件很大(5MB(。所以我想如果我确实发布,也许我可以减小尺寸,所以尝试使用 cargo build --release 命令发布,但收到此错误。

如果您使用的是 rustup 提供的二进制文件,那么这是上游的已知问题。 该问题有一个解决方法,即在Cargo.toml中设置以下内容:

[profile.release]
codegen-units = 1

作为替代方案,您可以使用 Debianrustccargo软件包而不是 rustup,这应该可以正常工作。 您可以从 https://packages.debian.org/rustc 和 https://packages.debian.org/cargo 下载软件包,也可以将适当的 APT 行添加到/etc/sources.list中(有关示例,请参阅 https://deb.debian.org/(。 请注意,Debian 并不总是有最新版本,但它们应该可以工作。

相关内容

最新更新