Home >Backend Development >Golang >How to Cross-Compile Go Programs from Windows to Linux?
Cross Compiling from Windows to Linux
Envision running a program compiled on a Windows machine flawlessly on a Linux system. Cross-compiling makes this scenario a reality. However, certain challenges arise when attempting to cross-compile from Windows to Linux.
Problem: Attempting to compile a program with "go build" while specifying a Linux target on Windows results in an error: "runtime: linux/amd64 must be bootstrapped using make.bat".
Answer: This error indicates a lack of necessary tools for cross-compilation. To resolve this issue, follow these steps:
Execute the following batch script to build the required tools:
set GOARCH=amd64 set GOOS=linux go tool dist install -v pkg/runtime go install -v -a std
Note: If your Windows GOARCH is "386", you will need to download mingw gcc and follow the instructions provided by user2714852.
For additional guidance, refer to the tutorial available at https://golang.org/wiki/WindowsCrossCompiling for instructions on cross-compiling from Linux.
The above is the detailed content of How to Cross-Compile Go Programs from Windows to Linux?. For more information, please follow other related articles on the PHP Chinese website!