大规模使用实时时未定义对主管道的引用 [英] Undefined reference to main when using Real-Time For the Masses

查看:95
本文介绍了大规模使用实时时未定义对主管道的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用大众实时(RTFM)为STM32F4Discovery编写多线程裸机应用程序板条箱。我已经从示例(用于STM32F3Discovery板)和此示例

I'm trying to write a multi-threaded bare-metal application for the STM32F4Discovery using the Real-Time For the Masses (RTFM) crate. I've frankensteined together a minimal application from an example for the STM32F3Discovery board and this example:

#![deny(unsafe_code)]
#![no_main]
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
extern crate cortex_m_semihosting;
extern crate panic_semihosting;
extern crate stm32f4;

use stm32f4::stm32f407;

use rtfm::app;

app! {
    device: stm32f407,
}

fn init(_p: init::Peripherals) {
}

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

我可以编译它,但与rust- lld失败,

I can get it to compile but linking with rust-lld fails with

= note: rust-lld: error: undefined symbol: main

我很困惑,因为当我运行货运扩展时,我会得到一个主要函数:

I am confused because when I run cargo expand I do get a main function:

fn main() {
    #![allow(path_statements)]
    let init: fn(init::Peripherals) = init;
    rtfm::atomic(unsafe { &mut rtfm::Threshold::new(0) },
                 |_t|
                     unsafe {
                         let _late_resources =
                             init(init::Peripherals{core:
                                                        ::stm32f407::CorePeripherals::steal(),
                                                    device:
                                                        ::stm32f407::Peripherals::steal(),});
                     });
    let idle: fn() -> ! = idle;
    idle();
}

我是Rust的新手(事实上,我希望学习这种语言

I'm new to Rust (in fact I was hoping to learn the language with this project) and have no idea where the error might be located.

推荐答案

当您要求编译器不要插入<$时c $ c> main ,程序中没有主符号。

As you ask the compiler to not insert main, there is no main symbol in your program.

Rust使用符号修饰,因此您的 main 函数没有名为 main 的符号。

Rust uses symbol mangling so your main function doesn't have a symbol named main.

答案取决于您的contextm,但通常应该这样做:

The answer depends on your contextm but generally this should do it:

#[no_mangle] // ensure that this symbol is called `main` in the output
pub extern fn main(argc: i32, argv: *const *const u8) -> i32 {

}

可以找到所有其他信息此处

All additional information can be found here

这篇关于大规模使用实时时未定义对主管道的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆