Sign up

Linker error

Hello,

I'm taking my first steps with D and Gtkd and tried to compile the hello world example from https://sites.google.com/site/gtkdtutorial, but when I try to compile the code, I get an linker error:

dmd -U/usr/include/d/gtkd-3 hello.d

hello.o:(.data.rel.ro+0x10): Warnung: undefinierter Verweis auf »_D3gtk10MainWindow12__ModuleInfoZ«
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

I've installed gtkd 3.7.3 from the Fedora 27 repositories. dmd is version 2.079.0.

The sample code I used:

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

Any ideas?

Re: Linker error

On 19-04-18 16:11, Marc wrote:

Hello,

I'm taking my first steps with D and Gtkd and tried to compile the hello world example from https://sites.google.com/site/gtkdtutorial, but when I try to compile the code, I get an linker error:

dmd -U/usr/include/d/gtkd-3 hello.d

Any ideas?

You will need to link with the GtkD library.

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

or you could use pkg-config:

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

Re: Linker error

Thanks Mike,

On Thu, 19 Apr 2018 19:02:23 +0200, Mike Wey wrote:

You will need to link with the GtkD library.

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

or you could use pkg-config:

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

When I use the commands like you mentioned, I still get the error messages by the linker:

dmd hello.d -I/usr/include/d/gtkd-3/ -L-L/usr/lib64/ -L-lgtkd-3 -L-ldl
hello.o: In Funktion »_Dmain«:
hello.d:(.text._Dmain[_Dmain]+0x15): Warnung: undefinierter Verweis auf »_D3gtk4MainQf4initFKAAyaZv«
hello.d:(.text._Dmain[_Dmain]+0x1c): Warnung: undefinierter Verweis auf »_D3gtk10MainWindowQm7__ClassZ«
hello.d:(.text._Dmain[_Dmain]+0x3d): Warnung: undefinierter Verweis auf »_D3gtk10MainWindowQm6__ctorMFAyaZCQBgQBfQBi«
hello.d:(.text._Dmain[_Dmain]+0x5f): Warnung: undefinierter Verweis auf »_D3gtk5LabelQg7__ClassZ«
hello.d:(.text._Dmain[_Dmain]+0x7f): Warnung: undefinierter Verweis auf »_D3gtk5LabelQg6__ctorMFAyabZCQBbQBaQBd«
hello.d:(.text._Dmain[_Dmain]+0xa3): Warnung: undefinierter Verweis auf »_D3gtk4MainQf3runFZv«
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

GTK libraries and development files are installed, but something is still missing.

Sorry if my questions are too stupid, but I'm new with D as well as with GTK3... ;-)

Re: Linker error

I have no clue why, but when I use ldc2 instead of dmd it works without problems. gdc unfortunately drops some other errors.

So the correct command to compile the example is:

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

Re: Linker error

On 19-04-18 22:27, Marc wrote:

I have no clue why, but when I use ldc2 instead of dmd it works without problems. gdc unfortunately drops some other errors.

So the correct command to compile the example is:

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

Yes, unfortunately the different compilers are not binary compatible, so
both the library and the application need to be compiled with the same
compiler.

Re: Linker error

Hi Mike,

On Thu, 19 Apr 2018 23:12:15 +0200, Mike Wey wrote:

Yes, unfortunately the different compilers are not binary compatible, so
both the library and the application need to be compiled with the same
compiler.

That means that gtkd on Fedora was compiled with ldc2? I think the Wiki should somehow reflect this, to be more beginner-friendly :-)

Thanks for the clarification!