Unable to compile GtkD SourceView code

I am new to gtk and d programming and learn using demos from gtkd source. when I try to compile the code below [I use dmd-2.060 and gtkd-2.0 in archlinux].

/* Modified sourceview demo for learning gtk programming in d */ pragma(lib, "gtkd"); pragma(lib, "gtkdsv"); pragma(lib, "dl"); import gtk.MainWindow; import gtk.Main; import gtk.Widget; //import gtk.TextView; import gsv.SourceView; import std.stdio; import std.file; /** * Demos for SourceView. * TODO on gsv: override methods from TextView, TextBuffer, etc */ class HelloWorld : MainWindow { SourceView sourceView; //TextView textView; this() { super("GtkD SourceView"); setBorderWidth(10); add(getSourceView()); setDefaultSize(640,400); showAll(); } private Widget getSourceView() { sourceView = new SourceView(); return sourceView; //textView = new TextView(); //return textView; } } void main(string[] args) { Main.init(args); new HelloWorld(); Main.run(); } 

I get errors like this

 /usr/lib/libgtkdsv.a(SourceCompletionInfo.o):(.data+0x140): undefined reference to `_D3gtk8TextView12__ModuleInfoZ' /usr/lib/libgtkdsv.a(SourceGutterRenderer.o):(.data+0xe8): undefined reference to `_D3gtk8TextView12__ModuleInfoZ' /usr/lib/libgtkdsv.a(SourceGutterRenderer.o): In function `_D3gsv20SourceGutterRenderer20SourceGutterRenderer7getViewMFZC3gtk8TextView8TextView': (.text._D3gsv20SourceGutterRenderer20SourceGutterRenderer7getViewMFZC3gtk8TextView8TextView+0x7e): undefined reference to `_D3gtk8TextView8TextView7__ClassZ' /usr/lib/libgtkdsv.a(SourceGutterRenderer.o): In function `_D3gsv20SourceGutterRenderer20SourceGutterRenderer7getViewMFZC3gtk8TextView8TextView': (.text._D3gsv20SourceGutterRenderer20SourceGutterRenderer7getViewMFZC3gtk8TextView8TextView+0x94): undefined reference to `_D3gtk8TextView8TextView6__ctorMFPS4gtkc8gtktypes11GtkTextViewZC3gtk8TextView8TextView' collect2: error: ld returned 1 exit status --- errorlevel 1 

But when I comment on the SourceView related code and uncomment the TextView related code, it compiles and works fine.

Note. This code is from the SVTest.d file in the demos gtkd sourceView folder.

Edit : I did dmd SVTest.d to compile that gave me this error, now I did dmd -L-ldl -L-lgtkd -L-lgtkdsv SVTest.d and it compiled fine. Now, if I delete the pragma instructions and try to compile with the compiler flags, this fails. I got a little confused here, D doc said the pragma was meant to pass information to the compiler! Do I need both pragma and compiler flags to compile the source code? or am i doing something wrong?

Update : indeed, pragma-order mattered, I changed the pragma to this

 pragma(lib, "gtkdsv"); pragma(lib, "gtkd"); pragma(lib, "dl"); 

Now I can just do

 dmd main.d 

which I originally wanted to do.

+4
source share
1 answer

I believe that the order of linker flags matters. gtkd loads shared objects and needs libdl, so -l-Ldl should be the first on the list. (which you did on the terminal)

Try moving the pragma (lib, "dl"); in first place and see if this has changed.

+1
source

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


All Articles