The problem with calling dlclose() here is that the libdl.a needs to be linked in to the D program to access the dlxxxx() functions. This is annoying for normal D programs. The solution is to move the functions that call the dlxxxx() functions into a separate module, hence a D program won't need to link in libdl.a unless it actually tries to dynamically load a DLL.

Alternatively, libdl.so could itself be dynamically loaded as required.