user101375 user101375 - 6 months ago 21
Linux Question

Using C++ Library in Linux (eclipse)

I wrote a library and want to test it. I wrote the following program, but I get an error message from eclipse.

#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv) {
void *handle;
double (*desk)(char*);
char *error;

handle = dlopen ("/lib/CEDD_LIB.so.6", RTLD_LAZY);
if (!handle) {
fputs (dlerror(), stderr);
exit(1);
}

desk= dlsym(handle, "Apply"); // ERROR: cannot convert from 'void *' to 'double*(*)(char*)' for argument 1
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}

dlclose(handle);
}


What is wrong?

Regards.

Answer

In C++ you need the following:


typedef double (*func)(char*);
func desk = reinterpret_cast<func>( dlsym(handle, "Apply"));
Comments