Dynamic D Library

BCS ao at pathlink.com
Mon Jul 27 13:34:44 PDT 2009


Reply to teo,

> I did some tests and here are the results: D cannot be used in Shared
> Objects. The only case that works is when no classes are exported and
> when there are no references to Phobos within the library.


this works:

module test;
int test1() { return 0; }
char[] test2() { return "hello world"; }

class C
{
    int i;
    this(int j) { i = j; }
    int get(){ return i; }
}

----

module main;
import test;
void main()
{
   test1();
   test2();
   int i = (new C(5)).get();
}

$ dmd -fPIC -c test.d
$ gcc -shared -o libtest.so test.o
$ dmd main.d -L-L`pwd` -L-ltest 

All the problems were resolved by replacing the prototypes with imports.





More information about the Digitalmars-d mailing list