Anyone knows how to use dynamic module loading through dlopen/dlsym/dlclose properly on FreeBSD?
I wrote a tiny program to learn KDE programming. Perhaps I give you a small snippet to look at
int IPTablesApp::Start(int argc, char* argv[]) {
typedef void (*init_t)(int, char*[]);
init_t init;
void *view = dlopen("./libkde-plugin.so", RTLD_NOW);
if (!view) {
// error loading libraries
fprintf(stderr, "Interface library load error: %s\n", dlerror());
return -1;
} else {
init = (init_t)dlsym(view, "_Init");
init(argc, argv);
}
dlclose(view);
return 0;
}
The KDE app is in libkde-plugin.so and is not shown here. Basically, when the app ends and execute the dlclose, gdb catches a segmentation fault for "Bad Address".
The same code runs okay on my Linux. Anyone can tell me if my way of using dl- functions are correct and are there workarounds (I saw some similar apps just comment out the dlclose line, but I don't know if this is proper or not)