www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - shared library in D

reply Frank Fischer <frank-fischer shadow-soft.de> writes:
Hi,

I want to write a shared library in D for use with C-code. The following
code shows a little example:

----
class A
{
  public:
    this()
    {
    }
}

extern(C) {
  void myfunc()
  {
    A a = new A();
  }
}
----

The function "myfunc" should be accessed from the C-code. But when I try
to create the shared library, I get the following error:

% dmd -O -release -c test.d
% gcc -shared test.o -lphobos
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/../../../../i686-pc-linux-gnu/bin/ld:
a.out: undefined versioned symbol name _d_throw 4
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/../../../../i686-pc-linux-gnu/bin/ld:
failed to set dynamic section sizes: Bad value
collect2: ld returned 1 exit status

So, what can be done (is it possible in general, what linker options are 
missed, what parts of D code are missing ...)?

Thx,
Frank
May 11 2004
parent John Reimer <brk_6502 NOSP_AM.yahoo.com> writes:
Frank Fischer wrote:
 Hi,
 
 I want to write a shared library in D for use with C-code. The following
 code shows a little example:
 
 ----
 class A
 {
   public:
     this()
     {
     }
 }
 
 extern(C) {
   void myfunc()
   {
     A a = new A();
   }
 }
 ----
 
 The function "myfunc" should be accessed from the C-code. But when I try
 to create the shared library, I get the following error:
 
 % dmd -O -release -c test.d
 % gcc -shared test.o -lphobos
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/../../../../i686-pc-linux-gnu/bin/ld:
 a.out: undefined versioned symbol name _d_throw 4
 /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/../../../../i686-pc-linux-gnu/bin/ld:
 failed to set dynamic section sizes: Bad value
 collect2: ld returned 1 exit status
 
 So, what can be done (is it possible in general, what linker options are 
 missed, what parts of D code are missing ...)?
 
 Thx,
 Frank
Unless things have changed, dmd still doesn't support creation of shared libraries on the Linux platform. See http://www.digitalmars.com/d/dcompiler.html. Look under Linux Bugs: "Shared libraries cannot be generated."
May 11 2004