Dynamic loading
Martin Nowak
code at dawg.eu
Tue Oct 29 08:13:44 PDT 2013
On 10/28/2013 07:00 PM, Steve Teale wrote:
>
> That sounds a bit implausible. New language keyword or something to load
> a library or object file. My best guess is that extern(C) dlopen() will
> just work correctly, failing that I'd think we need an equivalent Phobos
> call.
We need another runtime layer to account for per-thread
initialization/finalization of modules (static this()/static ~this()).
There is Runtime.loadLibrary/Runtime.unloadLibrary and
rt_loadLibrary/rt_unloadLibrary to do this.
You can use dlopen from a C executable but the loaded D library is only
usable from the loading thread.
For a C executable the recommended pattern is to dlopen or link druntime
(libphobos2.so) and to use rt_loadLibrary/rt_unloadLibrary to load D
libraries.
Currently the best available documentation are the tests
(https://github.com/D-Programming-Language/druntime/tree/master/test/shared).
More information about the Digitalmars-d
mailing list