D shared libraries

Unknown W. Brackets unknown at simplemachines.org
Sat Apr 12 00:28:51 PDT 2008


To compile a shared library, Linux using gdc:

gdmd -op -oflibxyz.so.1.0.1 lib.d -fPIC -q,-rdynamic,-shared
gdmd -op main.d -fPIC -q,-rdynamic -L-ldl

Compiling a shared library on Windows is a bit more complicated 
(although possible with dmd and phobos as they are.)  It involves 
DllMain and def files...

Please note, if you have selinux you may have have to run chcon.

-[Unknown]


BB wrote:
> Tried this on D.gnu but didn't get an answer.  Any feedback here?
> ------------------------------------------------------------------
> 
> 
>  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;
>     }
>     ...
> }
> 
> 
> 



More information about the Digitalmars-d mailing list