Cannot compile a simple #[no_std] program

For a "normal" Rust program compiled with the standard library, the standard library provides a shim normally called _start or mainCRTStartup which does some setup (initialize the heap, stash away environment variables, etc.) before calling into main(). Using the #[no_main] attribute tells the compiler that you'll provide this mainCRTStartup entrypoint function yourself, and we're getting a linker error because it wasn't defined.

When targeting a Windows platform the entrypoint will change depending on whether you target the "windows" subsystem (a GUI) or the "console", meaning you need to declare the appropriate extern "C" function as an entrypoint. I'd recommend looking through the Windows Subsystem RFC for the exact details.

You may also want to look at this thread on writing a #[no_std], #[no_main] win32 program... Which looks to be exactly what you're trying to do.

2 Likes