I\'m trying to compile the following simple DL library example code from Program-Library-HOWTO with g++. This is just an example so I can learn how to use and write shared libr
dlsym
returns a pointer to the symbol. (As void*
to be generic.)
In your case you should cast it to a function-pointer.
double (*mycosine)(double); // declare function pointer
mycosine = (double (*)(double)) dlsym(handle, "cos"); // cast to function pointer and assign
double one = mycosine(0.0); // cos(0)
So this one of these rare cases where the compiler error is a good clue. ;)