Using __cxa_atexit on Solaris

Tue Nov 16 21:25:00 GMT 2010


We recently had a weird memory corruption issue in our project during
destruction. The problem boiled down to order of destruction of
statics. They should have been destroyed in the exact reverse order of
the completion of their respective constructors. However gcc did not
preserve the order of destruction across block scope statics and
namespace scope statics.

According to this post (
msg01308.html), building gcc with  --enable-__cxa_atexit would solve
the issue. I built gcc 4.3.3 with this option but it still didn't seem
to solve the option. I also tried compiling the code with "-fuse-cxa-
atexit" option and got the following linking error.

/var/tmp//cc3nl8Dr.o: In function
`__static_initialization_and_destruction_0(int, int)':
temp.cpp:(.text+0x6a): undefined reference to `__cxa_atexit'
temp.cpp:(.text+0xaf): undefined reference to `__cxa_atexit'
temp.cpp:(.text+0xe0): undefined reference to `__cxa_atexit'
temp.cpp:(.text+0x13f): undefined reference to `__cxa_atexit'
temp.cpp:(.text+0x17c): undefined reference to `__cxa_atexit'
>::instance(char const*)]+0x6f): more undefined references to

`__cxa_atexit' follow
collect2: ld returned 1 exit status

My OS details are as follows - SunOS 5.10 Generic_127128-11 i86pc i386

Any suggestions on how to make it work?

View this message in context:
Sent from the gcc - Help mailing list archive at

More information about the Gcc-help mailing list