Linux Dynamic Loading of shared libraries

Anthony Goins neontotem at gmail.com
Sun Mar 9 11:37:30 PDT 2014


On Sunday, 9 March 2014 at 12:07:22 UTC, Steve Teale wrote:
> Martin Nowak's Gihub druntime Page has
>
> module main;
> import core.runtime, core.thread;
>
> void main() {
>     auto lib = Runtime.loadLibrary("./liba.so");
>     auto thr = new Thread({
>         auto lib = Runtime.loadLibrary("./liba.so");
>         Runtime.unloadLibrary(lib);
>     });
>     thr.start();
>     thr.join();
>     Runtime.unloadLibrary(lib);
> }
>
> module liba;
> import std.stdio;
>
> shared static this() { writeln("shared static this()"); }
> shared static ~this() { writeln("shared static ~this()"); }
> static this() { writeln("static this()"); }
> static ~this() { writeln("static ~this()"); }
>
> Now suppose that my D shared library contains a class, rather 
> that just module ctors/dtors, how do I go about creating an 
> instance of that class and using its methods?
>
> Steve
If you know the fully qualified name of the class and an interface
auto newClassIF = 
cast(interfacename)object.factory("libmodule.libclass");


More information about the Digitalmars-d-learn mailing list