Skip to content

Manually setting up a GDC tool chain on Debian Testing

AthanasiusOfAlex edited this page Nov 2, 2013 · 9 revisions

Introduction

This how-to gives step-by-step instructions for setting up GtkD manually on a Debian Testing system. (As of this writing, November 2, 2013, the latest release is Debian Jessie, and the version of Gtk used is 3.8.6.) It should be applicable, servatis servandis, to all GNU/Linux and Unix-like systems.

Packages to be installed.

The following packages should be installed.

  • libgtk-3-dev (version 3.8.6-1)
  • gdc-4.8 (version 4.8.2-1)

It is sufficient to install the latest versions from Debian Testing. These packages should pull in the necessary dependencies. Of course, Make and other essential elements of a development tool chain should be installed.

Setting up the install location.

  1. If necessary, create the folder where you want to install GtkD. For example, if you want it to be available system-wide, create /opt/gtkd; if you want it to be in your local user space, use /home/username/gtkd. (This tutorial will assume /home/username/gtkd throughout. Of course, the word "username" should be changed appropriately.)
  2. The compiler is called gdc-4.8; I suggest creating a shortcut called gdc:
cd /home/username/gtkd
mkdir bin
cd bin
ln -s /usr/bin/gdc-4.8 gdc

Alternatively, you can modify the make file. See below.

  1. To set up an environment that works correctly, you will have to set some environment variables. I suggest making a script called set_variables with the following contents:
#!/bin/sh

CPPFLAGS="-I/home/username/gtkd/include"
LDFLAGS="-L/home/username/gtkd/lib"
PKG_CONFIG_PATH="/home/username/gtkd/share/pkgconfig"
LD_LIBRARY_PATH="/home/username/gtkd/lib"
PATH="/home/username/gtkd/bin:$PATH"

export CPPFLAGS LDFLAGS PKG_CONFIG_PATH LD_LIBRARY_PATH PATH

I usually place the script in the directory /home/username/gtkd.

  1. You should invoke the script whenever you will use the tool chain. (Or else, if you want this environment to be default, you can add it to the appropriate profile scripts.) To use the script, using the terminal window from which you will be doing the compilation, type
. /home/username/gtkd/set_variables

(For those not familiar with shell scripts, note that . is short for source, which permits one to execute all of the commands in a shell script without ever leaving the current environment. Otherwise, the script will be executed in a "child" environment that is destroyed once the script is finished—which is no good for setting environment variables. The space between . and the file name is required.)

Compiling

  1. Download the GtkD source code and unzip it in an appropriate directory (for example, /home/username/gtkd/gtkd-2.3.0):
mkdir /home/username/gtkd/gtkd-2.3.0
cd /home/username/gtkd/gtkd-2.3.0
unzip /home/username/Downloads/GtkD-2.3.0.zip

(Of course, /home/username/Downloads represents whatever directory you downloaded the ZIP file to.)

  1. Modify the make file (GNUmakefile in /home/username/gtkd/gtkd-2.3.0) in a text editor. You will need to change the line prefix=/usr/local to reflect the installation directory. (For our purposes, change it to prefix=/home/username/gtkd.) The make file automatically detects if it is already installed, so if you want to force the compilation to use GDC, add the line DC=gdc just before the line ifndef DC. (If you opted not to make a symbolic link above, add DC=gdc-4.8 instead.)

  2. Making shared libraries still does not work for the moment. Thus, modify the line

all: libs shared-libs gda gstreamer vte shared-gda shared-gstreamer shared-vte test

removing all components that begin with the word "shared." The final result should be

all: libs gda gstreamer vte test

Note that the problem with pkg-config files that occurred in GtkD 2.2.0 has been fixed in version 2.3.0.

  1. Compile:
cd /home/username/gtkd/gtkd-2.3.0
make all
make install

If you are installing system-wide, the last command should instead be sudo make install.

Testing

  1. Try the program TestWindow:
cd /home/username/gtkd/gtkd-2.3.0
./TestWindow &
  1. Try compiling a demo program. For example, to make object files and then link them together, use the following:
cd /home/username/gtkd/gtkd-2.3.0/demos/cairo/cairo_clock
gdc -02 -c main.d `pkg-config --cflags gtkd-2` -o main.o
gdc -02 -c clock.d `pkg-config --cflags gtkd-2` -o clock.o
gdc -o cairoclock clock.o main.o `pkg-config --libs gtkd-2`

You can also compile and link in one step:

gdc -o cairoclock main.d clock.d `pkg-config --cflags --libs gtkd-2`

Now, try the program:

./cairoclock &

(If you opened up a brand new terminal window, don't forget to do . /home/username/gtkd/set_variables first. Of course, if you opted not to create a symbolic link to gdc-4.8, use substitute gdc-4.8 wherever necessary.)