libw32dl — dlopen and friends for mingw32
libw32dl is (yet another) emulation of the POSIX
dlopen, dlsym, dlerror and dlclose
functions for mingw32. Compared to other emulations, this one
- is really easy to incorporate into any program;
- is tiny (adding about 700 bytes to the main executable and each shared object);
- properly finds symbols 'defined' in the main .exe file but which in reality live in
an implicitly-loaded dll [Note 1];
- invokes _init() and _fini() at the appropriate times, if it can;
- makes symbols in RTLD_GLOBALly-opened modules available to the main executable and
to all shared objects via RTLD_DEFAULT, regardless of where (in the executable or
in a shared object) the module is dlopen()ed;
- pays lip service to RTLD_LOCAL and RTLD_GLOBAL
when searching the RTLD_DEFALT 'global namespace'.
- [Note 1]
- The thing that infuriated me into writing this
library was that 'nm' showed printf as a defined,
exported symbol in my main.exe file but
GetProcAdddress(GetModuleHandle(0), "printf") could not be
persuaded to find it. Grrrr.
There is no documentation, just the notes below and an example
program in the 'test' directory (type 'make test' in
the top-level directory to run it).
Download the source code: libw32dl-1.0.tar.gz
Browse the source code: libw32dl-1.0
Using the library
First compile the library: type 'make'.
For the main executable:
- include the header "w32dlfcn.h" in any source file that uses the dlopen API;
- include libw32dl.a when linking the final executable;
- arrange for the executable to export all the symbols that might be looked up by dlsym.
The simple-minded way to do this (and hence my preferred solution) is to pass
-Wl,--export-all-symbols to cc in the link command.
For each shared object:
- include the header "w32dlfcn.h" in any source file that uses the dlopen API;
- include libw32dl.a when linking the final shared object;
- make sure -shared is passed to cc in the link command;
- arrange for the shared object to export all the symbols that might be looked up by dlsym.
The simple-minded way to do this (and hence my preferred solution) is to pass
-Wl,--export-all-symbols to cc in the link command.
This has all been tested under mingw32 with GCC 3.4.4. However, it
was written in a hurry to satisfy an immediate need and so bugs may be
lurking.
libw32dl is distributed under the MIT license. It will not
infect your project with a contagious disease if you decide to use
and/or modify it.
If you fix any bugs, please send your fixes to Ian Piumarta by email
at 'first-name at last-name dot com'. Thanks!