ganesh
ganesh

Reputation: 43

Could not able to release a file. getting error: could not compile 'libc'

I am very new to this language and coding field. Beginner to coding field as well. I tried to build and release file but getting an error 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)

code: this program which i wrote in VS code to blink LED on raspberry pi 3

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 file:

[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"

I am getting output on Raspberry pi but executable file and binary files are large (5MB). So i thought if i do release maybe i can reduce size so tried to release using cargo build --release command but getting this error.

Upvotes: 3

Views: 4396

Answers (1)

bk2204
bk2204

Reputation: 77034

If you're using rustup-provided binaries, then this is a known issue upstream. There is a workaround in that issue, which is to set the following in Cargo.toml:

[profile.release]
codegen-units = 1

As an alternative, you can use the Debian rustc and cargo packages instead of rustup, which should work just fine. You can either download the packages from 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/ for an example). Note that Debian does not always have the latest version, but they should work.

Upvotes: 2

Related Questions