The benefits are evident - providing a uniform graphical user interface (GUI) when developing native programs. I definitely appreciated GTK+'s flexibility and portability when creating MoonDeploy, my cross-platform deployment tool.
The setup on Linux is generally very simple - on Ubuntu, for example, you'll just have to install the gcc compiler system and the required C libraries via the apt-get package manager.
In this short article we will see how to configure a 64-bit Windows system in order to develop a visual application.
We'll employ msys2, a brilliant development environment for Windows, including the MinGW-w64 compiler:
- Go to the msys2 website, download the installer having
x86_64in its name and run it
- Follow the wizard; we'll assume that msys is installed into the default directory
- As soon as the wizard has finished, run msys2's console (which should be suggested by the wizard itself)
In the console, run:
pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime
- Close and restart the console
- Restart the console
To install MinGW-w64, run:
pacman -S mingw-w64-x86_64-gcc
To install pkg-config, run:
pacman -S mingw64/mingw-w64-x86_64-pkg-config
- Add the following paths to your
Installing the GTK+ 3 libraries
Installing GTK+ 3 with msys2 requires a single instruction in msys2's console:
pacman -S mingw64/mingw-w64-x86_64-gtk3
Generally speaking, if you wish to look for a library whose you don't know the exact name, try running:
pacman -Ss text_to_search
Please, note: for 32-bit systems, the process is similar - just use a different installer and replace the x86_64 qualifier in package names.
Now, you can close msys2 - the installed tools will be available in DOS command windows as well.
- Install Go by downloading and running the installer from its website
- Set the GOROOT environment variable to Go's root directory
- Add Go's bin subdirectory to the PATH environment variable
- Create a directory that will be your Go path (for example, C:\GoPath)
- Assign such directory to the GOPATH environment variable
Installing GUI libraries for Go
This task usually requires Go's setup tool,
go get; in particular, for gotk3, you'll need to run, in a DOS command window:
go get github.com/gotk3/gotk3/gtk
If everything was installed correctly, the command should print no output, completing after a few minutes; otherwise, please double-check your msys2 setup.
Compiling a visual Go program
By default, on Windows, running GUI programs created with Go will show the DOS window as well, in the background.
To prevent this default behavior, you can compile the app by adding the following parameter to
-ldflags "-H windowsgui". For example:
go build -ldflags "-H windowsgui" SourceFile.go
On Linux, no additional arguments are required.