How can you cross-compile a Go program for different platforms using the Go toolchain?

  • Use the "go cross-compile" command.
  • Use the "go build" command with the "-o" flag and specify the target platform.
  • Use the "go run" command with the "-target" flag followed by the desired platform.
  • Use the "gox" third-party tool for cross-compilation.
To cross-compile a Go program, you can use the "go build" command with the "-o" flag followed by the desired output file name and the target platform. For example, to compile for Linux from a Windows machine, you can run: GOOS=linux GOARCH=amd64 go build -o myapp-linux. This will create an executable for Linux on an AMD64 architecture. This approach leverages the Go toolchain's built-in support for cross-compilation.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *