* problem with dlclose and destructors of global objects
@ 2004-05-12 10:37 Dominik Siatkowski
0 siblings, 0 replies; only message in thread
From: Dominik Siatkowski @ 2004-05-12 10:37 UTC (permalink / raw)
To: gcc-help
Hello.
I'm using gcc 3.3.2.
Here is simple example for problem that I encoutered.
test.cpp:
#include <dlfcn.h>
#include <stdio.h>
class klasa {
int m_a;
public:
klasa() {}
~klasa() {printf("~klasa\n");}
void set(int a) {m_a = a;}
int get() {return m_a;}
};
klasa Objekt;
int main(int a, char** b)
{
const char* lib = "libscaner.so";
Objekt.set(a);
if (a > 1)
lib = b[1];
void* h = dlopen(lib, RTLD_LAZY);
if (h == NULL) {
printf("Error on loading %s: %s", lib, dlerror());
return 1;
}
a=Objekt.get();
printf("loaded\n");
dlclose(h);
printf("closed\n");
return 0;
}
-------------------- end of test.cpp
testso.cpp:
#include <stdio.h>
class klasa {
int m_a;
public:
klasa2() {}
~klasa2() {printf("~klasa2\n");}
void set(int a) {m_a = a;}
int get() {return m_a;}
};
klasa2 Objekt2;
int dummy(int a) {
Objekt2.set(a);
return Objekt2.get();
}
-------------------- end of testso.cpp
I compile both files with command:
gcc -o test test.cpp -ldl -lstdc++
gcc -o libdupa.so testso.cpp -shared -fPIC
with gcc 3.3.2 on host with glibc 2.2.5.
When I run this test on the same host (and other with glibc 2.2.5 or 2.2.4)
all works ok:
$> ./test libdupa.so
loaded
~klasa2
closed
~klasa
But if I run the test on host with glibc 2.3.2 destructor of klasa is called
on dlclose:
&> ./test libdupa.so
loaded
~klasa
~klasa2
closed
Problem does not occur when I compile this test case on host with glibc
2.3.2.
Whats the problem? Is this gcc or glibc issue?
Is the problem fixed on newer gcc?
Regards
Dominik Siatkowski
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-05-12 10:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-12 10:37 problem with dlclose and destructors of global objects Dominik Siatkowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).