0

I have a set of classes defined within a namespace that I build into a C++ dynamic library under Linux. I'm trying to load in the dynamic library in an application and execute a function. My namespace looks something like this:

namespace myNamespace
{
    int myFunc(int);
}

If I do nm -F to look at the (demangled) symbols in the .so library file, I get something like:

000...0008345 W myNamespace::myFunc(int)

So the function is clearly in the .so file ok.

I open the file and get a handle to the function like this:

void* handle = dlopen(dll_path, RTLD_LAZY);

...handle any errors...

int (*f)(int);

f = (int (*)(int)) dlsym(handle, "myNamespace::myFunc");

char* errors = dlerror();

But this code doesn't work - I always get an 'undefined symbol' error. I tried removing the namespace scoping in the call to dlsym (i.e "myFunc" as the second argument), but it still doesn't work.

What am I doing wrong?

user12066
  • 613
  • 6
  • 23

0 Answers0