Skip to content

Commit

Permalink
cfg out the extern crate libc on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed May 19, 2024
1 parent 0d5f884 commit c56312b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/beneath-std.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ Note that the default features have been disabled. This is a critical step -
disabled.**

Alternatively, we can use the unstable `rustc_private` private feature together
with an `extern crate libc;` declaration as shown in the examples below.
with an `extern crate libc;` declaration as shown in the examples below. Note that
windows-msvc targets do not require a libc, and correspondingly there is no `libc`
crate in their sysroot. We not need the `extern crate libc;` below, and having it
on a windows-msvc target would be a compile error.

## Writing an executable without `std`

Expand All @@ -44,6 +47,7 @@ in the same format as C (aside from the exact integer types being used):
extern crate unwind;

// Pull in the system libc library for what crt0.o likely requires.
#[cfg(not(windows))]
extern crate libc;

use core::panic::PanicInfo;
Expand Down Expand Up @@ -78,6 +82,7 @@ compiler's name mangling too:
extern crate unwind;

// Pull in the system libc library for what crt0.o likely requires.
#[cfg(not(windows))]
extern crate libc;

use core::ffi::{c_char, c_int};
Expand Down

0 comments on commit c56312b

Please sign in to comment.