- 1 year ago
Error compiling GO project for windows using mingw32 on ubuntu
To compile a Go project for Windows using Mingw-w64 on Ubuntu, you can follow these steps:
Install Mingw-w64: Make sure you have Mingw-w64 installed on your Ubuntu system. You can install it using the package manager:
shellsudo apt-get install mingw-w64
Set Environment Variables: Set the environment variables required for cross-compilation. Open a terminal and run the following commands:
shellexport CC=x86_64-w64-mingw32-gcc
export CXX=x86_64-w64-mingw32-g++
export GOOS=windows
export GOARCH=amd64
These commands set the cross-compiler and specify the target operating system (Windows) and architecture (amd64).
Compile the Go Project: Navigate to the root directory of your Go project and use the
go build
command to compile the project:shellgo build -o output.exe
Replace
output.exe
with the desired name for your compiled executable.The
go build
command will use the cross-compiler specified by theCC
environment variable and generate a Windows executable.Test the Windows Executable: You can transfer the compiled executable (e.g.,
output.exe
) to a Windows machine and run it there.
By following these steps, you should be able to compile your Go project for Windows using Mingw-w64 on Ubuntu.