3.GOTK3 and Installation - gizemozgun/GOTK3 GitHub Wiki

GOTK3

The gotk3 project provides Go bindings for GTK+3 and dependent projects. Each component is given its own subdirectory, which is used as the import path for the package.Before you use Gotk3, please ensure you have the following components installed:

• GTK+3 (3.12 and later)
• GDK 3 (3.12 and later)
• GLib 2 (2.36 and later)
• Cairo (1.10 and later)

Installation

Gotk3 currently requires GTK 3.6-3.22, GLib 2.36-2.40, and Cairo 1.10 or 1.12. A recent Go (1.8 or newer) is also required. The gtk package requires the cairo, glib, and gdk packages as dependencies, so only one go get is necessary for complete installation.

To install gotk3 targeting the latest GTK version:

$ go get github.com/gotk3/gotk3/gtk

NOTE: The build process uses the tagging scheme gtk_MAJOR_MINOR to specify a build targeting any particular GTK version (for example, gtk_3_10). Building with no tags defaults to targeting the latest supported GTK release (3.22).

To install gotk3 targeting your version of GTK:

$ go get -tags gtk_X_XX github.com/gotk3/gotk3/gtk

To rebuild the package for another GTK version:

$ go install -tags gtk_X_XX github.com/gotk3/gotk3/gtk

## Installation instructions

Installing on Linux

Ubuntu / Debian

Ubuntu 14.04 uses the GTK 3.10 release. Also, some required packages may be missing. You may need to install the first or all of these packages in Ubuntu before gotk3:

$ sudo apt-get install libgtk-3-dev libcairo2-dev libglib2.0-dev

Fedora

$ sudo dnf install gtk3-devel cairo-devel glib-devel

Solus

$ sudo eopkg it libgtk-3-devel libcairo-devel

Clear Linux

$ sudo swupd bundle-add devpkg-gtk3

Installing on Windows

Getting gotk3 to work on Windows is little bit more difficult than it is on Linux systems.

Instaling Git

If you haven't already, be sure to install Git for Windows.The Windows version includes a bash shell and several useful Unix command line utilities, which are required.

Installing MinGW

The next step is to install MinGW-w64.Download the installer from here. These instructions are tested with version 4.8.1.

Install GTK and its dependencies

  1. first open MSYS
  2. Run the following command in order to install necessary dependencies for gotk3
    pacman --noconfirm --needed -Sy bash pacman pacman-mirrors
    pacman --noconfirm -Su
    pacman --noconfirm -S mingw-w64-x86_64-gcc mingw64/mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gtk3
    
  3. Apply a workaround for a bug that is currently present in the package config files (This will be a no op if the bug has been fixed already)
    bash -c "sed -i -e 's/-Wl,-luuid/-luuid/g' C:/msys64/mingw64/lib/pkgconfig/gdk-3.0.pc"
    

Modify your environment variables

The System Properties window must be opened to modify user and system environment variables. Opening this window varies slightly between Windows 7 and 8.

  • Windows 7: From the Start Menu, right click Computer, and select Properties. Click the 'Advanced system settings' link at the left, and then click the button labeled 'Environment Variables...'.

  • Windows 8: Right click the lower left corner (on Windows 8.1 this is the 'Start Screen' button) and select `System'. Click the 'Advanced system settings' link at the left, and then click the button labeled 'Environment Variables...'.

If this is a fresh Go installation and GOPATH has not been created, do so now:

mkdir -p ~/src/go To set the GOPATH environment variable, click New from the 'Environment Variables' window. In the dialog that opens, enter GOPATH for the variable name, and %USERPROFILE%\src\go for the value.

The Path environment variable must also be modified to include the folders containing mingw-w64 and Fedora binaries and DLLs. Modify the System Path variable by appending the string ;C:\Fedora\bin;C:\Program Files\mingw-builds\x64-4.8.1-posix-seh-rev5\mingw64\bin (the leading semicolon is to delimit the path from previous paths).

The changes made to the environment variables do not take effect immediately. On Windows 7, close and reopen all cmd.exe or git shell windows for the new environment variable changes to take effect. Windows 8 has changed this to require signing out and back in before any changes to the environment variables take effect.

Go get gotk3

With a compiler toolchain (MinGW-w64), pkg-config, and GTK with all dependencies installed, you should finally have a working build environment to install gotk3. From git bash, run:

go get github.com/gotk3/gotk3/gtk

If the above finished without outputting any errors, the install was successful.

Installing on OSX

The are two ways to install gotk3 on OSX. Users who prefer a more UNIX like system can install the first way and produce X11 apps. Users who prefer Mac native apps can install using the second method and build Mac native (quartz) apps. In either case, you must have a recent version (1.1 or later) of go installed and setup properly.

X11

When building to use X11, you must have the X11 version of gtk installed. The simplest way is to use a package manager such as [http://www.macports.org/]MacPorts. Using MacPorts, one can install gtk3 with the command:

$sudo port install gtk3

That should install all the required dependencies. You can then simply install gotk3 in the usual go way:

$ go get github.com/gotk3/gotk3/gtk

OSX Native

Building native Mac apps requires a few more steps. The Gnome project provides a tool, jhbuild, which simplifies this somewhat although there are still a few steps needed. It is very important that you do not have macports, fink, homebrew, or any other package manager (or its pacakges) in your path while building gtk+ for the mac. Once you have built and installed it, you can have them in your path again without a problem while building things and using gotk3. In the case of MacPorts, I commented out the line:

$ export PATH=/opt/local/bin:/opt/local/sbin:$PATH

from my .profile an then logged out and back in before building. Once finished building gtk, I put the line back in to allow me to work normally.

Download the build script from gnome.org:

curl https://gitlab.gnome.org/GNOME/gtk-osx/raw/master/gtk-osx-build-setup.sh
-o gtk-osx-build-setup.sh

Run the script:

sh gtk-osx-build-setup.sh

Assuming you are using bash (the default in OSX), you can set this alias to help use jhbuild

alias jhbuild="PATH=$HOME/gtk/bin:$PATH ~/.local/bin/jhbuild"

Install gtk+3 and all the required dependencies:

jhbuild bootstrap

jhbuild build meta-gtk-osx-bootstrap

jhbuild build meta-gtk-osx-core

jhbuild build meta-gtk-osx-gtk3

jhbuild can temporarily setup the environment for your shell to make sure all the paths are correct. You will only need this when you initially build the gotk3 library.

jhbuild shell

go get github.com/gotk3/gotk3/gtk

exit

You can now go back to your normal environment. It might be a good idea to build some of the samples provided to make sure everything works and to get some idea of what you can do:

cd $GOPATH/src/github.com/gotk3/gotk3-examples/gtk-examples/simple

go build

./simple

Now, you are ready!