Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

What's a main function?

In C programs, there's always a function named main that's called to start the application.

Mynewt OS is written in C, so Mynewt uses the same convention... It expects us to provide a C function named main that is called upon startup.

Our application is in Rust not C. We exposed our Rust function named main as a C function, like this...

extern "C" fn main()

Why is the main function in lib.rs not main.rs?

Our Rust Application is actually compiled into a Rust Library that's linked into Mynewt OS.

By convention, a Rust Library must have a lib.rs file that defines the Rust functions (and optionally, includes other Rust source files).

That's why our Rust main function is in lib.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.