plugin1.cpp:dlclose() nie wywołać destruktor globalnych obiektów
#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;
}
zbudować i uruchomić:
>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
dlaczego TestStatic :: ~ TestStatic wywołał w "exit()", ale nie w "dlclose()"?
Dobre pytanie: +1. – Chubsdad
Czy to pomocne? http://forum.soft32.com/linux2/dlclose-causing-segmentation-fault-exit-main-ftopict10002.html – Chubsdad
opcja -fno-use-cxa-atexit dla kompilacji plugin.cpp rozwiązuje problem – AndryBlack