Skip to content

Commit

Permalink
Use CONSOLE subsystem entry points; update link
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed Mar 14, 2018
1 parent 8d31229 commit 6599a69
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,18 @@ One way to pass linker attributes via cargo is the `cargo rustc` command. The co
With this command, our crate finally builds as a freestanding executable!

#### Windows
On Windows, the linker requires two entry points: `WinMain` and `WinMainCRTStartup`, [depending on the used subsystem](https://msdn.microsoft.com/en-us/library/f9t8842e.aspx). Like on Linux, we overwrite the entry points by defining `no_mangle` functions:
On Windows, the linker requires two entry points [depending on the used subsystem]. For the `CONSOLE` subsystem, we need a function called `mainCRTStartup`, which calls a function called `main`. Like on Linux, we overwrite the entry points by defining `no_mangle` functions:

[depending on the used subsystem]: https://docs.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol

```rust
#[no_mangle]
pub extern fn WinMainCRTStartup() -> ! {
WinMain();
pub extern fn mainCRTStartup() -> ! {
main();
}

#[no_mangle]
pub extern fn WinMain() -> ! {
pub extern fn main() -> ! {
loop {}
}
```
Expand Down

0 comments on commit 6599a69

Please sign in to comment.