How to build in #![no_std] #![no_main] do not understand

Example in documentation not build: (windows 8)

#![feature(no_std)]
#![no_std]
#![no_main]
#![feature(lang_items, start)]

extern crate libc;

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

#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }

Error "crate libcore nod found". Command -L "path to core" not work
maybe use #![no_core]? noo, not work :smiley:

Example is not build https://play.rust-lang.org/

in GCC command -e "entrypoint"
in Rust command or something else ?

Sorry my hard English

It won't work on play.rust-lang.org, because you can't use external crates.

If you remove the two lang lines, and make sure to change Cargo.toml to depend on libc, it works for me. Which documentation were you following?

1 Like

"remove the two lang lines, and make sure to change Cargo.toml to depend on libc" Get more errors.

Rephrase the question of how to collect the minimum program Rust without dependencies?

Minimum programm C (command line "-s -e _mstart -nostdlib main.c -o 1.exe")

[code]void mstart(void)
{

}[/code]

How to do it Rust?

[code]#![feature(no_std, no_core)]
#![no_std]
#![no_core]
#![no_main]

#[no_mangle]
pub extern fn start ()
{
}[/code]

#![feature(no_std)]
#![no_std]
#![no_main]
extern crate libc;
#[no_mangle]
pub extern fn main(argc: i32, argv: *const *const u8) -> i32 {
    0
}

will get you a minimum program with libc.

Note that you do need either libc or eh_personality and panic_fmt. Having both libc and manual definitions will be an error, but having neither is also an error.

When using libc, you also need to ensure that you depend on libc in your Cargo.toml. This is the Cargo.toml that I'm using that correctly compiles:

[package]
name = "raw"
version = "0.1.0"
authors = ["Dabo Ross <daboross@daboross.net>"]

[dependencies]
libc = "0.1"
1 Like

Thanks to for the detailed answer.

I would like to discuss details but prevents Google translation.

thank you guys!

1 Like