Getting started with gtkd

I am new to D and want to experiment with gtkd. I am on arch linux and install the dmd2-complete (dmd 2.0.56) and gtkd-svn (gtkd built against D2) packages. I also confirmed that D itself worked correctly (compiled and ran the writefln("hello world"); base program writefln("hello world"); ).

Now I'm trying to start gtkd and work, and it is very difficult for me to compile and link the helloworld core program with 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(); } 

In particular, what parameters do I need to pass to dmd to bind this? Almost all the documentation I can find completely skips this.

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

  /usr/lib/libgtkd.a /usr/lib/libgtkdgl.a /usr/lib/libgtkdsv.a 
+4
source share
4 answers

Ok, so I found the answer in the sidebar of related questions. Leaving this here, since Google was not looking for another thread when I searched, and maybe he was lucky with that. You need to pass the linker options as -Ll , in particular in this case

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

and everything works beautifully.

+5
source

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

So I can’t say for sure, since I didn’t use gtkD, but something like -L-lgtkd should do the trick.

if not, play with -L-lgtkdg1, etc. one of em should be right.

Edit: just add more information ... the linker will automatically search for / usr / lib and a few other places. I believe the linker action is identical to the C binding process, so you can find out more information on how C links.

+3
source

I program in Gentoo and I manually compile dmd and gtkD.
So in the beginning I type:

 echo $PKG_CONFIG_PATH 

It does not get anything.
I do this: In ~/.bashrc:

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

because there is everything we need.
Then I type:

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

and the output of this I copy and paste into:
/etc/dmd.conf
to section: "[Environment]"
to the variable: "DFLAGS" (at the end).
A clean installation of dmd and gtkD (by copying and pasting) should look like this:
(/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/ -LL/usr/local/lib/ -L-lgtkd-2 -L-ldl 

Now I can compile my D programs as follows:
dmd myprog.d

That's all!

P.S
Sorry for my English.

+2
source

You can also use pkg-config :

 dmd `pkg-config --cflags --libs gtk-2` hellogtk.d 
+1
source

Source: https://habr.com/ru/post/1383033/


All Articles