Last active
August 29, 2025 16:15
-
-
Save Mefistophell/9787e1b6d2d9441c16d2ac79d6a505e6 to your computer and use it in GitHub Desktop.
Revisions
-
Mefistophell revised this gist
Jul 7, 2023 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #### **Question**: I want to compile my Rust source code for the Windows platform but I use macOS. ### Solution: 1. Install target mingw-w64: `brew install mingw-w64` 2. Add target to rustup: `rustup target add x86_64-pc-windows-gnu` @@ -10,22 +10,22 @@ [target.x86_64-pc-windows-gnu] linker = "x86_64-w64-mingw32-gcc" ``` 5. If it's not working try to run the following command: ``` cp -f /usr/local/Cellar/mingw-w64/7.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/lib/{,dll}crt2.o `rustc --print sysroot`/lib/rustlib/x86_64-pc-windows-gnu/lib ``` 6. And finally, run: `cargo build --target=x86_64-pc-windows-gnu --verbose` ### Useful commands: `rustup show` — shows targets amn toolchain `rustup target list` — shows all supported targets **A bit of theory:** To compile a source code for a platform different from your local, you need to specify a target. This tells the compiler which platform your code should be compiled for. For this reason, you need to install the appropriate GCC, the GNU Compiler Collection for Windows. Like this one: [mingw-w64](https://formulae.brew.sh/formula/mingw-w64). Then you should add the target to the Rust toolchain. > *Toolchains* are a set of linked tools that help the language produce a functional target code. They can provide extended functionality from either a simple compiler and linker program, or additional libraries -
Mefistophell revised this gist
Jan 28, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ cp -f /usr/local/Cellar/mingw-w64/7.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/li **A bit of theory:** To compile your source code for another platform, you need to specify a target. This tells the compiler which platform your code should be compiled for. For this reason, you need to install the appropriate GCC, the GNU Compiler Collection for Windows. Like this one [mingw-w64](https://formulae.brew.sh/formula/mingw-w64). Then you should add a target to a Rust toolchain. -
Mefistophell revised this gist
Jan 28, 2020 . No changes.There are no files selected for viewing
-
Mefistophell revised this gist
Jan 28, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,4 +40,5 @@ Links: - [Cargo configuration](https://doc.rust-lang.org/cargo/reference/config.html) - [Introduction to the compiler, linker, and libraries](https://www.learncpp.com/cpp-tutorial/introduction-to-the-compiler-linker-and-libraries/) - [Github issue: Can't cross compile from Linux to Windows](https://github.com/rust-lang/rust/issues/32859) - [Github issue: Cannot link with C code using stdout](https://github.com/rust-lang/rust/issues/47048) - [Rust Toolchains](https://medium.com/@nsdchrisu/rust-is-distributed-on-a-stable-nightly-and-beta-release-channels-5ebf18126c0d) -
Mefistophell revised this gist
Jan 28, 2020 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ cp -f /usr/local/Cellar/mingw-w64/7.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/li `rustup target list` shows all supported targets. **A bit of theory:** To compile your source code for another platform, you need to specify a target. This tells the compiler which platform your code should be compiled for. For this reason, you need to install the appropriate GCC, the GNU Compiler Collection for Windows. Like this one [https://formulae.brew.sh/formula/mingw-w64](mingw-w64). @@ -36,8 +36,8 @@ The next step is to add a linker. This can be set in the *Cargo config* When the linker is added you can build a program. Links: - [Download mingw-w64 via Homebrew](https://formulae.brew.sh/formula/mingw-w64) - [Cargo configuration](https://doc.rust-lang.org/cargo/reference/config.html) - [Introduction to the compiler, linker, and libraries](https://www.learncpp.com/cpp-tutorial/introduction-to-the-compiler-linker-and-libraries/) - [Github issue: Can't cross compile from Linux to Windows](https://github.com/rust-lang/rust/issues/32859) - [Github issue: Cannot link with C code using stdout](https://github.com/rust-lang/rust/issues/47048) -
Mefistophell revised this gist
Jan 28, 2020 . 1 changed file with 31 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,43 @@ #### **Q**: I want to compile my Rust source code for the Windows platform, but I work on macOS. ### Solution 1. Install target mingw-w64: `brew install mingw-w64` 2. Add target to rustup: `rustup target add x86_64-pc-windows-gnu` 3. Create `.cargo/config` 4. Add the instructions below to `.cargo/config` ``` [target.x86_64-pc-windows-gnu] linker = "x86_64-w64-mingw32-gcc" ``` 5. If it hasn't work this is supposed to help: ``` cp -f /usr/local/Cellar/mingw-w64/7.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/lib/{,dll}crt2.o `rustc --print sysroot`/lib/rustlib/x86_64-pc-windows-gnu/lib ``` 6. And finally, run: `cargo build --target=x86_64-pc-windows-gnu --verbose` ### Useful commands: `rustup show` shows targets amn toolchain `rustup target list` shows all supported targets. **A bit of theory: ** To compile your source code for another platform, you need to specify a target. This tells the compiler which platform your code should be compiled for. For this reason, you need to install the appropriate GCC, the GNU Compiler Collection for Windows. Like this one [https://formulae.brew.sh/formula/mingw-w64](mingw-w64). Then you should add a target to a Rust toolchain. > *Toolchains* are a set of linked tools that help the language produce a functional target code. They can provide extended functionality from either a simple compiler and linker program, or additional libraries The next step is to add a linker. This can be set in the *Cargo config* > The Rust compiler sequentially goes through each source code file in your program and checks your code to make sure it follows the rules of the Rust language and translates your source code into a machine language file called an object file. After the compiler creates one or more object files, then another program called the **linker** take all the object files generated by the compiler and combine them into a single executable program. In addition to being able to link object files, the **linker** also is capable of linking library files. A library file is a collection of precompiled code that has been “packaged up” for reuse in other programs. When the linker is added you can build a program. Links: - [https://formulae.brew.sh/formula/mingw-w64](Download mingw-w64 via Homebrew) - [https://doc.rust-lang.org/cargo/reference/config.html](Cargo configuration) - [https://www.learncpp.com/cpp-tutorial/introduction-to-the-compiler-linker-and-libraries/](Introduction to the compiler, linker, and libraries) - [https://github.com/rust-lang/rust/issues/32859](Github issue: Can't cross compile from Linux to Windows) - [https://github.com/rust-lang/rust/issues/47048](Github issue: Cannot link with C code using stdout) -
Mefistophell created this gist
Jan 28, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 1. Install target mingw-w64: `brew install mingw-w64` 2. Add target to rustup: `rustup target add x86_64-pc-windows-gnu` 3. Create .cargo/config 4. Add the instructions below to `.cargo/config` ``` [target.x86_64-pc-windows-gnu] linker = "x86_64-w64-mingw32-gcc" ``` 5. Fix cert ``` cp -f /usr/local/Cellar/mingw-w64/7.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/lib/{,dll}crt2.o `rustc --print sysroot`/lib/rustlib/x86_64-pc-windows-gnu/lib ``` 6. And finally, run: `cargo build --target=x86_64-pc-windows-gnu --verbose` Useful commands: rustup show rustup target list