Skip to content

Manually setting up a GDC tool chain on Debian Testing

AthanasiusOfAlex edited this page Jul 24, 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, July 24, 2013, the latest release is Debian Jessie, and the version of Gtk used is 3.8.2.) 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.2-3)
  • gdc-4.8 (version 4.8.1-2)

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 modify the appropriate profile scripts accordingly. 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-220):
mkdir /home/username/gtkd/gtkd-220
cd /home/username/gtkd/gtkd-220
unzip /home/username/Downloads/GtkD-2.2.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-220) 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.) If necessary, modify the line DC=gdc to DC=gdc-4.8. (This last step is not necessary if you made the symbolic link gdc above.)

  2. There appears to be a bug in one of the pkg-config files produced by GtkD 2.2.0. Search for the line gtkd-$(MAJOR).pc:. The next line that begins echo Libs: should be replaced with

echo Libs: $(LINKERFLAG)-lgtkd-$(MAJOR) $(LINKERFLAG)-L$(prefix)/lib/ $(LINKERFLAG)-ldl >> $@

(Alternatively, you can modify the file gtkd-2.pc, which will be installed in /home/username/gtkd/shared/pkgconfig, later on. See below.)

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

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

  1. Verify that the file gtkd-2.pc is correct. Open it in a text editor, and verify that the Libs: section reads
Libs: -Xlinker -lgtkd-2 -Xlinker -L/home/username/gtkd/lib -Xlinker -ldl

If you did not modify the corresponding part of the make file, you will need to modify gtkd-2.pc appropriately now.

Testing

  1. Try the program TestWindow:
cd /home/username/gtkd/gtkd-220
./TestWindow &
  1. Try compiling a demo program. For example:
cd /home/username/gtkd/gtkd-220/demos/cairo/cairoclock
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`
./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 the latter instead.)