Could not able to release a file. getting error: could not compile 'libc'
Could not able to release a file. getting error: could not compile 'libc'
我对这个语言和编码领域很陌生。编码领域的初学者也是如此。
我尝试构建和发布文件但出现错误 Compiling 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 代码编写的,用于在 raspberry pi 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 提供的二进制文件,那么这是 known issue upstream。该问题有一个解决方法,即在 Cargo.toml
中设置以下内容:
[profile.release]
codegen-units = 1
作为替代方案,您可以使用 Debian rustc
和 cargo
软件包而不是 rustup,它应该可以正常工作。例如,您可以从 https://packages.debian.org/rustc and https://packages.debian.org/cargo, or you can add an appropriate APT line into /etc/sources.list
(see https://deb.debian.org/ 下载软件包)。请注意,Debian 并不总是有最新版本,但它们应该可以使用。
我对这个语言和编码领域很陌生。编码领域的初学者也是如此。 我尝试构建和发布文件但出现错误 Compiling 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 代码编写的,用于在 raspberry pi 3
上闪烁 LEDuse 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 提供的二进制文件,那么这是 known issue upstream。该问题有一个解决方法,即在 Cargo.toml
中设置以下内容:
[profile.release]
codegen-units = 1
作为替代方案,您可以使用 Debian rustc
和 cargo
软件包而不是 rustup,它应该可以正常工作。例如,您可以从 https://packages.debian.org/rustc and https://packages.debian.org/cargo, or you can add an appropriate APT line into /etc/sources.list
(see https://deb.debian.org/ 下载软件包)。请注意,Debian 并不总是有最新版本,但它们应该可以使用。