Shared library in D on Linux

Timo Westkämper" <timo.westkamper at gmail.com> Timo Westkämper" <timo.westkamper at gmail.com>
Sun Apr 8 10:41:13 PDT 2012


On Sunday, 8 April 2012 at 14:52:55 UTC, Ellery Newcomer wrote:
> On 04/08/2012 03:45 AM, "Timo Westkämper" 
> <timo.westkamper at gmail.com>" wrote:
>>
>> extern(C) {
>>
>> void gc_init();
>> void gc_term();
>>
>> void _init() {
>> gc_init();
>> }
>>
>> void _fini() {
>> gc_term();
>> }
>>
>> }
>
> I think you want rt_init and rt_term here.

I got now the simple example working:

* Makefile:
#!/bin/bash
test:
	dmd -lib -g -c test.d -fPIC
	ld -shared -o libtest.so test.a -lrt -lphobos2 -lpthread
	gcc -g main.c -ldl -lpthread
	./a.out
clean:
	rm -rf *.a *.so *.o *.out

* test.d:
import std.stdio;
extern (C) void hiD() {
   writeln("hi from D lib");
}

Compiling as lib did the track and added the missing parts.

I will now advance with more complex examples.





More information about the Digitalmars-d mailing list