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 :: ~ टेस्टस्टैटिक 'एक्जिट()' पर बुलाया जाता है लेकिन 'dlclose()' पर नहीं?
अच्छा प्रश्न: +1। – Chubsdad
क्या यह सहायक है? http://forum.soft32.com/linux2/dlclose-causing-segmentation-fault-exit-main-ftopict10002.html – Chubsdad
विकल्प -fno-use-cxa-atexit compilation plugin.cpp समस्या हल करने के लिए – AndryBlack