Question

I'm new to D, and want to experiment with gtkd. I'm on arch linux, and installed the dmd2-complete (dmd 2.0.56) and gtkd-svn (gtkd built against D2) packages. I also verified that D itself was working properly (compiled and ran a basic writefln("hello world"); program).

Now I'm trying to get gtkd up and running, and am having a very hard time compiling and linking the basic helloworld program from the examples.

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();
}

Specifically, what options do I need to pass to dmd to get this to link? Pretty much all the documentation I can find skips over this entirely.

The gtkd-svn package has installed the following in /usr/lib:

 /usr/lib/libgtkd.a
 /usr/lib/libgtkdgl.a
 /usr/lib/libgtkdsv.a
Was it helpful?

Solution

Okay, so I found the answer in the "related questions" sidebar. Leaving this up here since google didn't bring up the other thread when I was searching, and it might have better luck with this one. You need to pass in the linker options as -L-l, specifically in this case

dmd -L-lgtkd -L-ldl hellogtk.d

and everything works nicely.

OTHER TIPS

dmd passes flags to the linker after the -L flag.

So I cannot say for certain, since I haven't used gtkD, but something like -L-lgtkd should do the trick.

if not, play around with -L-lgtkdg1 and stuff.. one of em is bound to be right.

Edit: just adding extra info... the linker will automatically search /usr/lib and a few other places. I believe that the linker action is identical to the C process of linking, so more information can be gleaned from looking at how C links.

I am programming on the Gentoo and I am manually compile dmd and gtkD.
So, at the start I type:

echo $PKG_CONFIG_PATH

That gets me nothing.
I do that: In ~/.bashrc:

( ... )
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig

because there is all that we need.
Then I type:

pkg-config gtkd-2 --cflags --libs

and the output of this I copy and paste to:
/etc/dmd.conf
to section: "[Environment]"
to variable: "DFLAGS" ( at the end ).
Clean install dmd and gtkD ( by copy and paste ) should look like that:
( /etc/dmd.conf )

( ... )
[Environment]
DFLAGS=-I/usr/include/phobos2 -I/usr/include/druntime -L--no-warn-search-mismatch -L--    export-dynamic -L-lrt -I/usr/local/include/d/gtkd-2/ -L-L/usr/local/lib/ -L-lgtkd-2 -L-ldl

At now I can compile my D programs like that:
dmd myprog.d

That`s all !

P.S.
Sorry for my English.

You can use also pkg-config:

dmd `pkg-config --cflags --libs gtk-2`  hellogtk.d
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top