At first I want to apologize for my English. I want to rewrite my Java program to D. I have problem with shared library and dlopen() function.

calc_mean.d:

extern(C){
     double mean(double a, double b) {
             return (a+b) / 2;
     }
}

dmd -fPIC calc_mean.d -c
gcc -shared -Wl,-soname,libmean.so.1 -o libmean.so.1.0.1  calc_mean.o -m32


test.d:

import std.stdio;
import std.c.linux.linux ;

public void main(){
     void *handle;
     double (*reff)(double, double);

     handle = dlopen("./libmean.so.1.0.1", RTLD_NOW);

     char *errstr = dlerror();

     if(errstr != null)
          printf ("A dynamic linking error occurred: (%s)\n", errstr);

     *cast(void **)(&reff) = dlsym(handle, "mean");
     errstr = dlerror();

     if(errstr != null)
          printf ("A dynamic linking error occurred: (%s)\n", errstr);

     writefln((*reff)(1,12));
}



dmd test -L-ldl

./test :

./test
A dynamic linking error occurred: (./libmean.so.1.0.1: undefined symbol: _Dmodule_ref)
A dynamic linking error occurred: (./test: undefined symbol: mean)
Segmentation fault

I am 17, so I am novice programmer. I don't know what I am doing wrong. Please help me.