我是这个语言和编码领域的新手。也是编码领域的初学者。 我尝试构建和释放文件,但是在编译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命令来发布,但出现此错误。
答案 0 :(得分:0)
如果您使用的是rustup提供的二进制文件,则这是known issue upstream。该问题中有一个解决方法,可以在Cargo.toml
中进行以下设置:
[profile.release]
codegen-units = 1
作为替代方案,您可以使用Debian rustc
和cargo
软件包而不是rustup,它们应该可以正常工作。您可以从https://packages.debian.org/rustc和https://packages.debian.org/cargo下载软件包,也可以在/etc/sources.list
中添加适当的APT行(有关示例,请参见https://deb.debian.org/)。请注意,Debian并不总是具有最新版本,但是它们应该可以工作。