Skip to content

Instantly share code, notes, and snippets.

@zvodd
Last active December 23, 2020 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zvodd/83fe37abb81cd0ebea771bdce409c276 to your computer and use it in GitHub Desktop.
Save zvodd/83fe37abb81cd0ebea771bdce409c276 to your computer and use it in GitHub Desktop.
Building Go CGO on windows

Install Msys2 Open the MSYS terminal run the updates and then enter these commands.

pacman -Syu

Close and Re-Open Msys2 Terminal

pacman -Su

pacman -Sy base-devel mingw-w64-x86_64-gcc

Add bin folder to MSYS Home

mkdir ~/bin

Put ~/bin on the path

echo export PATH="\$PATH:~/bin" >> ~/.bashrc

#create envgo command (empty)

touch ~/bin/envgo

chmod u+x ~/bin/envgo

nano ~/bin/envgo

Now you need to open ~/bin/envgo and past the following (edited suitably). If you installed go in C:\Go then the correct path is /c/Go

export GOPATH=/c/GOPATH
export GOROOT=/c/Go
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH

To use:

Open MSYS2 MinGW 64-bit terminal: Type (DOT) envgo

. envgo

Navigate to your module folder or go path:

cd /c/some_go_module

go build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment