How do I compile a go program on Linux to a windows executable?
- User
How do I compile a go program on Linux to a windows executable?
- Assistant
You can easily cross-compile code written in Go for Windows, macOS, and Linux by using the
GOARCHandGOOSenvironmental variables, which represent the compilation architecture and the name of the target operating system respectively. They are set to your host compilation architecture (GOHOSTARCH) and operating system (GOHOSTOS) by default. You need to modify these values in order to compile for Windows instead of Linux.Here’s the command you need to run to compile your Go project for a 64-bit Windows machine:
$ GOOS=windows GOARCH=amd64 go build -o bin/app-amd64.exe app.goIn this scenario,
GOOSis windows, andGOARCHis amd64 indicating a 64-bit architecture. Thego build -o bin/app-amd64.exe app.gocommand compiles app.go into a .exe compatable with 64-bit versions of Windows. If you need to support a 32-bit architecture, all you need to do is changeGOARCHto 386.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.