Skip to content

Commit 0da67c0

Browse files
committed
README.md: Add cross-compiling guide for Linux to Windows
Signed-off-by: Lilis Iskandar <[email protected]>
1 parent e322b42 commit 0da67c0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,22 @@ func main() {
100100
}
101101
```
102102

103+
For more complete examples, see inside the _examples_ folder. Run any of the .go files with `go run`.
103104

104105

105-
For more complete examples, see inside the _examples_ folder. Run any of the .go files with `go run`.
106+
Cross-compiling
107+
===============
108+
109+
### Linux to Windows
110+
111+
1. Install MinGW toolchain.
112+
* On **Arch Linux**, it's simply `pacman -S mingw-w64`.
113+
2. Download the SDL2 development package for MinGW [here](http://libsdl.org/download-2.0.php).
114+
3. Extract the SDL2 development package and copy the `x86_64-w64-mingw32` folder inside recursively to the system's MinGW `x86_64-w64-mingw32` folder. You may also do the same for the `i686-w64-mingw32` folder.
115+
* On **Arch Linux**, it's `cp -r x86_64-w64-mingw32 /usr`.
116+
4. Now you can start cross-compiling your Go program by running `env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-I/usr/x86_64-w64-mingw32/include/SDL2 -D_REENTRANT" go build -x main.go`. You can change some of the parameters if you'd like to. In this example, it should produce a `main.exe` executable file.
117+
5. Before running the program, you need to put `SDL2.dll` from the [SDL2 runtime package](http://libsdl.org/download-2.0.php) for Windows in the same folder as your executable.
118+
6. Now you should be able to run the program using Wine or Windows!
106119

107120
FAQ
108121
===

0 commit comments

Comments
 (0)