dynamic library building and loading

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Sep 27 12:57:50 PDT 2012


On 9/27/12 3:37 PM, Maxim Fomin wrote:
> Posted code doesn't load libraries at runtime, it is just linked to
> shared libraries.

Exactly! (I can't believe I'm starting to get the hang of this...) But 
what we ultimately need is true dynamic loading of never-seen modules.

After the initial test I tried to load symbols with dlopen(). Indeed 
this works:

auto p = dlopen("liblib.so", RTLD_LAZY);

And it does work, all fine. To my dismay, as soon as I removed the flag 
"-llib" from the linker command line in the makefile, dlopen() didn't 
want to work anymore.

So I think in order to enable "true" dynamic loading, I'll need to 
generate PIC for druntime and phobos, and then link liblib.so like this:

dmd -fPIC -c lib.d
gcc -shared lib.o -o liblib.so -L/path/to/phobos -lphobos2

Is that correct?

At that point, of course, a variety of issues will need to be resolved 
as people pointed out.


Andrei


More information about the Digitalmars-d mailing list