We have a minimal working example of dlopen that works.
void* lib = dlopen("servlets.so", RTLD_NOW);
void* p = dlsym(lib, "getServlets");
However, if we add another function to the shared library (not even if it is called) then the library does not work (even though the code is never called)
uint32_t count = 0;
Servlet** servlets;
extern "C" {
void generate() {
servlets = new Servlet*[3];
servlets[0] = new Servlet(...);
}
Servlet** getServlets() { return servlets; }
uint32_t getServletNum() { return count; }
}
This must be because the code in the shared object is referencing some symbol that we don't have, but we do not know what. The code compiles and links without a problem.
Is there any way to find out what the error is? No error is reported, except that the library pointer returns NULL and the library does not load.
How do we link to a library so that dlopen works?