darchlinuxgtkd

Can't compile GtkD SourceView code


I am new to gtk programming and d and learning using demos from gtkd source. when i try to compile the code below [ i am using dmd-2.060 and gtkd-2.0 on 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 SourceView related code and uncomment TextView related code it compiles and runs fine.

Note: This code is from SVTest.d file on sourceView gtkd demos directory.

Edit: I was doing dmd SVTest.d to compile which was giving me that error now i did dmd -L-ldl -L-lgtkd -L-lgtkdsv SVTest.d and it compiled fine. Now if i remove the pragma statements and try to compile with compiler flags it fails. I am bit confused here, D doc said pragma was for passing information to compiler! do i need both pragma and compiler flags to compile source code? or am i doing something wrong?

Update: Indeed the pragma order mattered, I changed pragma to this

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

Now i can just do

dmd main.d

which i was originally wanting to do.


Solution

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

    Try moving pragma(lib, "dl"); to the first spot, and see if that makes a difference.