Sign up

Can someone guide me on how to setup gtkD?

Hello, I'm running Ubuntu 19.04,
I would like to see a working gtkD example on my system finally.

However it seems it is not that simple as just:

  • sudo snap install --classic dmd
  • apt-get install libgtkd-3-dev
  • And running some examples from
    http://www.dsource.org/projects/gtkd/wiki/CodeExamples
  • rdmd hello.d

What I'm missing and how should I setup for the examples to run correctly?

Right now I'm getting

vaidas@vaidas-SATELLITE-L855:~$ rdmd hello.d 
hello.d(1): Error: module `MainWindow` is in file 'gtk/MainWindow.d' which cannot be read
import path[0] = .
import path[1] = /snap/dmd/62/bin/../import/druntime
import path[2] = /snap/dmd/62/bin/../import/phobos
Failed: ["/snap/dmd/62/bin/dmd", "-v", "-o-", "hello.d", "-I."]

Re: Can someone guide me on how to setup gtkD?

On 09-06-2019 21:52, boqsc wrote:

Hello, I'm running Ubuntu 19.04,
I would like to see a working gtkD example on my system finally.

However it seems it is not that simple as just:

  • sudo snap install --classic dmd
  • apt-get install libgtkd-3-dev
  • And running some examples from

http://www.dsource.org/projects/gtkd/wiki/CodeExamples

  • rdmd hello.d

What I'm missing and how should I setup for the examples to run correctly?

Right now I'm getting

vaidas@vaidas-SATELLITE-L855:~$ rdmd hello.d
hello.d(1): Error: module `MainWindow` is in file 'gtk/MainWindow.d' which cannot be read
import path[0] = .
import path[1] = /snap/dmd/62/bin/../import/druntime
import path[2] = /snap/dmd/62/bin/../import/phobos
Failed: ["/snap/dmd/62/bin/dmd", "-v", "-o-", "hello.d", "-I."]

The gtkd package in the debian/ubuntu repository is compiled with ldc,
this means your GtkD application also needs to be compiled with ldc.

To compile the application while passing the correct flags to the
compiler you can use pkg-config:

ldc2 `pkg-config --cflags --libs gtkd-3` hello.d

The call to pkg-config would expand to:

-I/usr/include/d/gtkd-3/ -L-lgtkd-3 -L-ldl

Re: Can someone guide me on how to setup gtkD?

Thank you, now it works and I can see the example running.

Terminal command

rdmd -I/usr/include/d/gtkd-3/ -L-lgtkd-3 -L-ldl hello.d 

hello.d

import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main(string[] args)
{
    Main.init(args);
    MainWindow win = new MainWindow("Hello World");
    win.setDefaultSize(200, 100);
    win.add(new Label("Hello World"));
    win.showAll();
    Main.run();
}

The result:

alt text

For those that do not have D lang or/and gtkD installed:
I tested on another Ubuntu 19.04 system, and it seems that it was pretty straight forward to setup D lang and gtkD for the first time:

sudo snap install --classic dmd
sudo apt-get install libgtkd-3-dev 

Re: Can someone guide me on how to setup gtkD?

Even more simple approach to setup gtkD.

Since gtkD is available as dub package, we can simply install dub package manager, which will take care of our gtkD dependency leading to a very simple way to setup everything. https://code.dlang.org/packages/gtk-d

Follow these steps to install required software:

sudo snap install --classic dmd
sudo snap install dub

After successful installation, create a new text file and simply drop your "example application" program inside it:

hello.d

#!/usr/bin/env dub
/+ dub.sdl:
	name "hello"
	dependency "gtk-d" version="*"
+/
import gtk.MainWindow;
import gtk.Label;
import gtk.Main;

void main(string[] args)
{
    Main.init(args);
    MainWindow win = new MainWindow("Hello World");
    win.setDefaultSize(200, 100);
    win.add(new Label("Hello World"));
    win.showAll();
    Main.run();
}

Use dub package manage to run your hello.d example via:

dub hello.d

The result is the same:
An example program