gpt4 book ai didi

rust - 根据 xargo,我的代码已成功构建,但目标中没有二进制文件,为什么?

转载 作者:行者123 更新时间:2023-11-29 08:27:09 26 4
gpt4 key购买 nike

我是 Rust 的新手,所以如果我还不知道术语/工具,请原谅我。我正在尝试让 STM32F4 使 LED 闪烁,我认为代码是正确的,但是当我构建它时 xargo 不会生成二进制或任何类型的错误。我的代码是:

#![feature(proc_macro)] // <- IMPORTANT! Feature gate for procedural macros
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f40x;

use cortex_m::peripheral::SystClkSource;
use rtfm::{app, Threshold};

app! {
device: stm32f40x,
resources: {},
tasks: {
SYS_TICK: {
path: toggle,
resources: [GPIOC],
},
},
}

fn init(p: init::Peripherals, _r: init::Resources) {
// TODO: initialize the GPIO
p.SYST.set_clock_source(SystClkSource::Core);
p.SYST.set_reload(8_000_000); // 1s?
p.SYST.enable_interrupt();
p.SYST.enable_counter();
}

fn idle() -> ! {
loop {
rtfm::wfi();
}
}

fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) {
**r.GPIOC.odr.modify(|r, w| w.odr13().bit(!r.odr13().bit()));
}

Cargo.toml 文件是

[package]
name = "sign_firmware"
version = "0.0.1"
authors = ["teryret"]
categories = ["embedded", "no-std"]
description = "With any luck this will cause an STM32F4 based board to drive a few thousand LEDs."
keywords = ["arm", "cortex-m"]
license = "MIT OR Apache-2.0"
repository = "TODO"
[dependencies]
cortex-m = "*"
cortex-m-rt = "*"
cortex-m-rtfm = "*"
stm32f40x = "*"

[profile]
[profile.release]
debug = true
lto = true

[target.arm-none-linux-gnueabihf]
ar = "arm-linux-gnueabihf-gcc-ar"
linker = "arm-linux-gnueabihf-gcc"

当我在 docker 镜像中运行 xargo build --release 时,我设置为包含所有依赖项以及它说的诸如此类的东西:

teryret@bee ~/d/rtfm> ./build 
Compiling core v0.0.0 (file:///usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
Finished release [optimized + debuginfo] target(s) in 12.82 secs
Updating git repository `https://github.com/rust-lang-nursery/compiler-builtins`
Compiling compiler_builtins v0.1.0 (https://github.com/rust-lang-nursery/compiler-builtins#f5532b22)
Finished release [optimized + debuginfo] target(s) in 2.12 secs
warning: unused manifest key: target.arm-none-linux-gnueabihf.ar
warning: unused manifest key: target.arm-none-linux-gnueabihf.linker
Downloading cortex-m-rtfm v0.2.1
Downloading stm32f40x v0.5.0
Downloading cortex-m-rt v0.3.6
Downloading cortex-m v0.3.1
Downloading rtfm-core v0.1.0
Downloading static-ref v0.2.1
Downloading cortex-m-rtfm-macros v0.2.0
Downloading error-chain v0.10.0
Downloading quote v0.3.15
Downloading rtfm-syntax v0.1.0
Downloading syn v0.11.11
Downloading unicode-xid v0.0.4
Downloading synom v0.11.3
Downloading volatile-register v0.2.0
Downloading bare-metal v0.1.1
Downloading aligned v0.1.1
Downloading vcell v0.1.0
Downloading r0 v0.2.2
Compiling r0 v0.2.2
Compiling libc v0.2.33
Compiling vcell v0.1.0
Compiling quote v0.3.15
Compiling cc v1.0.3
Compiling sign_firmware v0.0.1 (file:///usr/src/myapp)
Compiling cortex-m-rt v0.3.6
Compiling cortex-m-rtfm v0.2.1
Compiling cfg-if v0.1.2
Compiling rustc-demangle v0.1.5
Compiling bare-metal v0.1.1
Compiling unicode-xid v0.0.4
Compiling aligned v0.1.1
Compiling cortex-m v0.3.1
Compiling static-ref v0.2.1
Compiling volatile-register v0.2.0
Compiling synom v0.11.3
Compiling rtfm-core v0.1.0
Compiling syn v0.11.11
Compiling stm32f40x v0.5.0
Compiling backtrace-sys v0.1.16
Compiling backtrace v0.3.4
Compiling error-chain v0.10.0
Compiling rtfm-syntax v0.1.0
Compiling cortex-m-rtfm-macros v0.2.0
Finished release [optimized + debuginfo] target(s) in 47.2 secs

虽然在 target 中生成了很多东西/它们都不是二进制文件,但我可以闪存到板上。知道为什么吗?我的意思是,它必须是简单的东西,但我没有经验知道去哪里找。

最佳答案

tutorial you were following , 所有 examples are in an "examples" directory .您可以使用 --example 参数构建它们,如教程中所示:

xargo build --example hello

但是,如果这是您的主要程序,您将希望将代码放在 "src/main.rs" 中,只允许:

xargo build

如果你有多个可执行文件,你可以also specify that .

关于rust - 根据 xargo,我的代码已成功构建,但目标中没有二进制文件,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47367793/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com