tags:

views:

2104

answers:

2

Hi all!

I work in Linux with c++ (eclipse) and want to use a library. Eclipse shows me an error: undefined reference to 'dlopen'

Do you know a solution?

Here is my code.

#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");

    if ((error = dlerror()) != NULL)  {
        fputs(error, stderr);
        exit(1);
    }

    dlclose(handle);
}
+10  A: 

You have to link against libdl, add

-ldl

to your linker options

Masci
A: 

You needed to do something like this for the makefile:

LDFLAGS='-ldl' make install

That'll pass the linker flags from make through to the linker. Doesn't matter that the makefile was autogenerated.

Rob