
import std.stdio, core.sys.posix.dlfcn;

void main() {

  auto handle = dlopen("./libdload.so".ptr, RTLD_LAZY | RTLD_GLOBAL);
  if( handle==null ) { writeln("!1"); return; }

  dload = cast(typeof(dload)) dlsym(handle, "dload".ptr);
  if( dload==null ) { writeln("!2"); return; }

  string concat_symbol = dload("concat"); //get mangled names
  string sum_symbol = dload("sum");

  concat = cast(typeof(concat)) dlsym(handle, concat_symbol.ptr );
  sum = cast(typeof(sum)) dlsym(handle, sum_symbol.ptr );
  if( concat==null || sum==null ) { writeln("!3"); return; }

  writeln( concat("Hello", " this is a call ", "of concat") );
  writeln( "3 + 4 + 5 via sum is ", sum(3,4,5) );
}

string function(string) dload; //name mangling function in libdload.so

//D functions to dynamically load
string function(string[] arg...) concat;
int function(int[] num...) sum;
