[Ubuntu] Linking to static libraries

simendsjo simendsjo at gmail.com
Wed Mar 28 03:34:46 PDT 2012


On Wed, 28 Mar 2012 12:05:59 +0200, Minas <minas_mina1990 at hotmail.co.uk>  
wrote:

> There's a small C graphics library called GP142, which I am trying to  
> port to D on Linux (Ubuntu).
>
> So I compiled the library in gcc, and that gave me the file gp142.o  
> which I must link together with my D source file.
>
> My code is very simple. I declare the two simplest functions in GP142,  
> and try to call them. If it works, I will do the same for all the other  
> functions :)
>
> However, GP142 must be linked with the Xlib library in order to work.
> When compiling as a C program, I would say something like: [gcc test.c  
> gp142.o -o test -lX11] and it would work.
>
> How can do this with dmd? (Note that X11 is somewhere in the system, not  
> in my project folder - gcc manages to find though).
>
>
> This my code:
>
> import std.stdio;
>
> extern (C) int GP142_open();
> extern (C) void GP142_close();
>
> void main()
> {
> 	// initialize GP142
> 	GP142_open();	
>
> 	// close GP142
> 	GP142_close();
> 	
> 	writeln("Works");
> }

To pass -lX11 to the linker, dmd has the -L flag.
"dmd -L-lX11" will pass "-lX11" to the linker.


More information about the Digitalmars-d-learn mailing list