I'm not sure if thats a built-in capable feature of DLL or SO linkable libraries(considering that the idea is that they are linkable to any other program) BUT you can always just call a common function at the end of each program that uses the DLL/SO or if you have an initialize/finalize(deinitialize) set of functions for your libraries then you can simply include a call to this function in your deinit code.

Interesting idea though....