Dynamically Loading a D DLL From a D Program

Benjiro via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 14 13:38:27 PST 2016


Silly question: In this post about static / dynamic loading, i 
noticed that it uses the dlopen/dlclose, while there is a 
core.runtime for handling the loading.

http://dlang.org/dll-linux.html#dso9

Dynamically Loading a D DLL From a D Program

>  void* lh = dlopen("libdll.so", RTLD_LAZY);
>
>  // Do Stuff
>
>  dlclose(lh);

Is it not better to use:

> import core.runtime : Runtime;
>
> void* lib = Runtime.loadLibrary(fileName);
> 
> // Do Stuff
>
>  Runtime.unloadLibrary(lib);

Is there also any information regarding d classes loading instead 
of functions?

It also seems that the core runtime is incomplete with basic 
loading but no handling of dlsym, so your still forced to use the 
basic c conversion casting.

> int function() fn = cast(int function())dlsym(lib, libFunction);
> fn();


More information about the Digitalmars-d-learn mailing list