www.digitalmars.com         C & C++   DMDScript  

D.gnu - D shared libraries

reply BB <b.buderman gmail.com> writes:
 From what I read on newsgroups, this should be possible with gdc on 
linux?  Goal is a plugin type solution.  With the following code, I 
compile intf.d and lib.d together into a shared library, and intf.d and 
main.d into an executable.  Compiles/links fine.  When I run it, I get a 
message like:

Null library handle: libxyz.so.1.0.1: undefined symbol: __data_start

I compiled the .d files with -fPIC and the .so with:
gcc -shared -Wl,-soname,libxyz.so.1 -fPIC.

Is this definitely possible, and if so, what am I doing wrong?  I tried 
gdc 0.24 and the latest off svn with the same results.

TIA.

-------------------------------------------------------------

intf.d:
=========
module intf;
public interface I { public int getId(); }

lib.d:
=========
module lib;
import intf;
class A : I { public int getId() { return 42; } }
extern (C) { I getObj() { return new A(); } }

main.d:
==========
...
void main(char[][] args)
{
     void* hnd = dlopen(toStringz("libxyz.so.1.0.1"), RTLD_NOW);
     if (hnd == null) {
         printf("Null library handle: %s\n", dlerror());
         return 0;
     }
     ...
}
Apr 09 2008
parent Gregor Richards <Richards codu.org> writes:
BB wrote:
  From what I read on newsgroups, this should be possible with gdc on 
 linux?  Goal is a plugin type solution.  With the following code, I 
 compile intf.d and lib.d together into a shared library, and intf.d and 
 main.d into an executable.  Compiles/links fine.  When I run it, I get a 
 message like:
 
 Null library handle: libxyz.so.1.0.1: undefined symbol: __data_start
 
 I compiled the .d files with -fPIC and the .so with:
 gcc -shared -Wl,-soname,libxyz.so.1 -fPIC.
 
 Is this definitely possible, and if so, what am I doing wrong?  I tried 
 gdc 0.24 and the latest off svn with the same results.
 
 TIA.
 
 -------------------------------------------------------------
 
 intf.d:
 =========
 module intf;
 public interface I { public int getId(); }
 
 lib.d:
 =========
 module lib;
 import intf;
 class A : I { public int getId() { return 42; } }
 extern (C) { I getObj() { return new A(); } }
 
 main.d:
 ==========
 ...
 void main(char[][] args)
 {
     void* hnd = dlopen(toStringz("libxyz.so.1.0.1"), RTLD_NOW);
     if (hnd == null) {
         printf("Null library handle: %s\n", dlerror());
         return 0;
     }
     ...
 }
 
 
 
Check the rebuild configuration for GDC, it has all the flags and such necessary to both create and host .so's. Note that creating .so's is not all that well supported though. http://svn.dsource.org/projects/dsss/trunk/rebuild/rebuild.conf/gdc-posix - Gregor Richards
Apr 11 2008