digitalmars.D.learn - Dynamically Loading a D DLL From a D Program
- Benjiro (11/21) Dec 14 2016 Silly question: In this post about static / dynamic loading, i
- Nicholas Wilson (2/16) Dec 14 2016 There is also derelict shared lib loader in derelict-util in dub.
- Guillaume Piolat (3/9) Dec 15 2016 You can use the derelict-util library to load a dynlib portably.
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 Programvoid* 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();
Dec 14 2016
On Wednesday, 14 December 2016 at 21:38:27 UTC, Benjiro wrote: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 ProgramThere is also derelict shared lib loader in derelict-util in dub.[...]Is it not better to use:[...]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.[...]
Dec 14 2016
On Wednesday, 14 December 2016 at 21:38:27 UTC, Benjiro wrote: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.You can use the derelict-util library to load a dynlib portably. https://github.com/DerelictOrg/DerelictUtil/blob/2de2a9b63f8cdfbd8270afa8a4dc28f4ffaa868c/source/derelict/util/sharedlib.d#L110int function() fn = cast(int function())dlsym(lib, libFunction); fn();
Dec 15 2016