I'm trying to build a shared library that another program will load at runtime, but I'm getting an undefined symbol error when I call dlopen() on the library. The missing symbol is a function (call it foo_func) defined in the main project where my program is built (and used in the main program as well), and I'm including its header in the shared library definition.
Based on other posts on stackoverflow, I've tried using the -fPIC and -shared flags to build my library, and -rdynamic -ldl to build my main program, but still get the error. The library roughly looks like this. Any ideas what could be wrong?
#include <header where foo_func is defined>
class foo {
public:
foo() {x=0;}
virtual void init(){};
double x;
};
class bar: public foo{
public:
void init() {
foo_func(...)
}
};
extern "C" foo* create() { return new bar; }
<header where foo_func is defined>is not something anyone could ever try and compile. Build an MVCE please. - n. 1.8e9-where's-my-share m.dlerror()when something is failing - Basile Starynkevitch