Compiling with no_std on windows

Hi,

I was wondering if anyone had a working example of compiling anything with no_std on Windows. I copy pasted the exact piece of code here:

https://doc.rust-lang.org/unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib

There's a stack overflow thread that appears to talk about this issue but the suggested fix is to just use the second option presented in the above link. Both seem to end complaining about unresolved symbols.

There's a Reddit thread here from there years ago with the same issues:

https://www.reddit.com/r/rust/comments/h8qvuo/building_with_no_std_on_i686pcwindowsmsvc/

Where advise is that it's resolved by using compiler_builtins crate, but that didn't seem to do anything. I get differing errors depending what you do but the most common compile error would be:

          libcore-b86a9ba077d96bbb.rlib(core-b86a9ba077d96bbb.core.b3bcec111bdf2857-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol memcmp
          LINK : error LNK2001: unresolved external symbol mainCRTStartup

mainCRTStartup is the real entry point of the executable. This function is normally provided by libc and initializes libc before calling the main function written by the user. When using #![no_std] by default libc isn't linked in. You can either tell rustc to link it yourself or write mainCRTStartup yourself. Note that it must be an extern "stdcall" function.

I've seen multiple suggestions for "link it yourself" regarding libc, from this:

#![feature(lang_items, libc, core_intrinsics, rustc_private)]

To extern crate libc;. I've got all of them in that example and I can't seem to get anywhere.

Does #[link(name = "msvcrt")] extern "C" {} work?

My goodness, that did it.

Actually after hours of searching, right when you posted I found this thread and was wondering if there was a deeper bug:

but nope, you got it. Thanks a tonne!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.