$ cat host.d import std.exception; import core.runtime; import core.sys.posix.dlfcn; import common; void main(string[] args) { auto lib = Runtime.loadLibrary(args[1]).enforce("Failed to load library"); auto getter = cast(Getter*)dlsym(lib, "getInstance").enforce("Failed to get `getInstance`"); auto instance = (*getter)(); instance.foo(); } $ cat a.d import common; class Baz : Bar { override void foo() { import std.stdio; writeln("It works!"); } } extern(C) Bar getInstance() { return new Baz; } $ cat common.d interface Bar { void foo(); } extern(C) Bar getInstanceDL(); alias Getter = typeof(getInstanceDL); $ cat build.sh # NOTE: you must create a symlink the shared version of Phobos or update the # rpath references appropriately DC="dmd" # Host $DC -g host.d common.d -L-ldl -map -defaultlib=libphobos2.so -L-rpath=. # a.so $DC -c a.d -fPIC -ofa.o common.d $DC -ofa.so a.o -shared -defaultlib=libphobos2.so -L-rpath=. $./build.sh $./host "$PWD/a.so" Fatal Error while loading '/home/justin/workspace/aiasflow/tests/interfaces/a.so': The module 'common' is already defined in './host'. Segmentation fault