[Ubuntu] Linking to static libraries

Minas minas_mina1990 at hotmail.co.uk
Wed Mar 28 03:05:59 PDT 2012


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


More information about the Digitalmars-d-learn mailing list