plugin1.cpp的析構函數:dlclose()不會調用全局對象
#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;
}
構建和運行:
>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
爲什麼TestStatic :: 〜TestStatic在'exit()'處調用,但不在'dlclose()'處調用?
好問題:+1。 – Chubsdad 2010-09-28 06:29:42
對您有幫助嗎? http://forum.soft32.com/linux2/dlclose-causing-segmentation-fault-exit-main-ftopict10002.html – Chubsdad 2010-09-28 06:31:52
選項-fno-use-cxa-atexit用於編譯plugin.cpp解決問題 – AndryBlack 2010-09-28 07:00:12