plugin1.cpp:dlclose() nicht die destructor der globalen Objekte nennen
#include <iostream>
static class TestStatic {
public:
TestStatic() {
std::cout << "TestStatic create" << std::endl;
}
~TestStatic() {
std::cout << "TestStatic destroy" << std::endl;
}
} test_static;
host.cpp
#include <dlfcn.h>
#include <iostream>
int main(int argc,char *argv[]) {
void* handle = dlopen("./plugin1.so",RTLD_NOW | RTLD_LOCAL);
dlclose(handle);
return 0;
}
bauen und laufen:
>g++ -c plugin1.cpp -o plugin1.o -fPIC
>g++ -shared plugin.o -o plugin1.so
>g++ host.cpp -o host -ldl
>./host
>TestStatic create
>Segmentation fault
warum TestStatic :: ~ TestStatic bei 'exit()' aufgerufen aber nicht bei 'dclclose()'?
Gute Frage: +1. – Chubsdad
Ist das hilfreich? http://forum.soft32.com/linux2/dlclose-causing-segmentierung-fault-exit-main-ftopict10002.html – Chubsdad
Option-fno-use-cxa-atexit zum Kompilieren plugin.cpp Problem zu lösen – AndryBlack