Golang compile go-gl example on Windows in Mingw 64

Martin Kunc
3 min readJan 13, 2020

When using Golang on Windows sooner or later you will run in need of CGO, or in other words gcc compiler suite for Windows. Golang relies on gcc and g++ compilers installed in your system. I wanted to create some nice guide which shows how make it all working.

There are few projects, msys, cygwin, mingw or tdm-gcc. I will use mingw, the 64bit version, which should be just a compiler suite (unlike msys, which has many packages) and not needed extra library (online cygwin).

Downloading package:

This page http://mingw-w64.org/doku.php
Has Downloads, link to sourceforge

Over there is a section
MingW-W64-builds

Which leads to sourceforge.net and that will offer download. If link is invalid, click Problems Downloading? And choose another mirror site.

Installation:

When downloaded package is started, most important step is to set-up gcc options correctly. I will be using latest Version (8.1 in my case, but might be higher).

Architecture should be x86_64,
the Threads should be posix and
Exception should be sjlj.

Like on this picture:

I will not install to program files, but rather to d:\, you might find c:\mingw-w64 more suitable. It is generally because we want the path to be shorter to add it in PATH more easily in next steps.

When installed, I will check where gcc.exe really is:

And in a cmd I will add that folder to path using:

setx path “%PATH%;D:\mingw-w64\mingw64\bin”

Then I will check if path is set (the new path is added to the end:

Now, we need to check if gcc works. We need to restart cmd and when gcc is called, result should look like this:

By default, GOPATH folder is expected to be in c:\Users\[youruser]\go. If you don’t have go folder there, create it:

Using: mkdir %USERPROFILE%\go

Next, we can check if go env has CGO_ENABLED set to 1, CC is set to gcc and CXX is set to g++, eventually try to execute (run gcc or g++). It should return error similar to above — no input files.

Finally, we can try to get some for example go-gl example using:
go get -u github.com/go-gl/example/gl41core-cube

And go to that folder:
cd %USERPROFILE%\go\src\github.com\go-gl\example\gl41core-cube

And run:
go run cube.go

This should be the desired output.

--

--