user101375 user101375 - 1 year ago 137
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/", RTLD_LAZY);
if (!handle) {
fputs (dlerror(), stderr);

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


What is wrong?


Answer Source

In C++ you need the following:

typedef double (*func)(char*);
func desk = reinterpret_cast<func>( dlsym(handle, "Apply"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download