Is it possible for a running c++ based process to reload a c++ based dynamic library using dlopen
.
The running process polls for a new version of the dynamic library (with the same API). once such file is detected, the following set of actions are taking place :
- The older Library gets unloaded using
dlclose
- The newer dylib is copied and override the file of the older version.
- The process loads the newer version from that location using
dlopen
- Setting the function pointer variables according to
dlsym
from the newly loaded library.
In the last stage, I actually get the desired API and place it in function pointer from my main code to be used later.
However, it seems like my program is unexpectedly gets crashed after the third phase. is it possible that the dlclose
part leave some remnants of the older library in the process virtual space ? is there any better way to do so ?
by the way, in Windows it's working just fine using LoadLibrary, FreeLibrary and GetProcAddress
instead of dlopen, dlclose and dlsym
.
dlsym
. – Bellwortdlsym
(see updated question), isn't there any way that the linker gets confused with the older symbols (that have the same name) ? – Milestone