首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法释放文件。获取错误:无法编译'libc‘

无法释放文件。获取错误:无法编译'libc‘
EN

Stack Overflow用户
提问于 2019-10-10 15:56:56
回答 1查看 1.8K关注 0票数 1

我对这个语言和编码领域非常陌生。初学者到编码领域也是如此。我尝试构建并发布文件,但在编译libc v0.2.62时遇到错误

代码语言:javascript
复制
error: Could not compile `libc`
代码语言:javascript
复制
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

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
[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命令来发布,但得到了这个错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-11 06:41:18

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

代码语言:javascript
复制
[profile.release]
codegen-units = 1

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58318039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档