In a C++ class, I need to call functions that come from a dynamically loaded library. I get the function pointers like this:
typedef void (*TDef_libfunc)(); // also tried extern "C" typedef void (*TDef_libfunc)();
my_libfunc = (TDef_libfunc)dlsym(thelibrary, "libfunc");
(The lib function is loaded, I see it in the debugger.)
my_libfunc is declared as a member variable like this:
TDef_libfunc my_libfunc;
From within a member function of that class, I try to call my function pointer like this:
my_libfunc();
But it crashes… Am I doing this right? Is it possible to have a member variable that is a pointer to a C function?
Simple library compiled using gcc (if you compile will g++ you will need to add extern “C”).
Simple program that will load the above library (path and function hard-coded).
I had a seg fault because I had an declared fn_ as a pointer.
I tested and compiled this under Ubuntu 10.04 using the compiler from the repository.