Undefined reference to main when using Real-Time For the Masses

不羁的心 提交于 2019-12-13 18:13:51

问题


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();
    }
}

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();
}

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.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/52425667/undefined-reference-to-main-when-using-real-time-for-the-masses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!