Status of Dynamically Loadable D Libraries

Dave Wilson boff1984 at hotmail.com
Sun Feb 10 17:21:46 PST 2013


You can arrange to have d's runtime initialized when dlopen loads
the shared lib by adding a small shim that uses gcc attributes,
as follows:

// shim.c

__attribute__((constructor))
static void dinit() {
      rt_init();
}
__attribute__((destructor))
static void dfini() {
      rt_term();
}

// end of shim.c

Compile this to a .o with gcc, then include the .o in the build.
Note that I've only tried this trick with a simple "hello world"
shared lib, so I apologize in advance if it doesn't work for
real-world uses.


More information about the Digitalmars-d mailing list