Thread View: comp.sys.sgi.bugs
2 messages
2 total messages
Started by Harold Zatz
Mon, 04 Jan 1993 22:17
C++ atexit() doesn't work
Author: Harold Zatz
Date: Mon, 04 Jan 1993 22:17
Date: Mon, 04 Jan 1993 22:17
28 lines
983 bytes
983 bytes
On an Elan R4000, running 4.0.5F, with a version of the C++ library
that looks like:
krazy % ll /usr/lib/libC.a
-r--r--r-- 1 root wheel 161188 Oct 2 19:48 /usr/lib/libC.a
atexit() doesn't work with C++. Try this program:
-----test.c-----
#include <stdlib.h>
#include <stdio.h>
void doMe() {
fprintf( stderr, "atexit() works!\n" );
}
main() {
atexit( doMe );
exit( 0 );
}
-------
krazy % cc -o test test.c
krazy % test
atexit() works!
krazy % CC -o test test.c
krazy % test
Fixes? Workarounds? Anyone?
--Harold Zatz
Re: C++ atexit() doesn't work
Author: Shankar Unni
Date: Tue, 05 Jan 1993 01:43
Date: Tue, 05 Jan 1993 01:43
59 lines
1852 bytes
1852 bytes
Harold Zatz (hzatz@cco.caltech.edu) wrote:
> krazy % CC -o test test.c
> krazy % test
An artifact of the woefully unportable AT&T C++ library. It has a
replacement for "exit()" that is totally bogus (it's pre-ANSI C, and
doesn't look for atexit() functions).
> Fixes? Workarounds? Anyone?
Solution (it's a little crude for the moment):
1. Create the following compilation unit:
exit.c:
/* --- cut here --- */
extern "C" {
extern void _exit(int);
extern void __call_exitfns();
extern void _cleanup();
}
extern void __dtors();
extern "C" {
extern void exit(int i);
}
extern void exit(int i)
{
__call_exitfns(); /* This is the fix */
__dtors();
_cleanup();
_exit(i);
}
/* --- cut here --- */
2. To use this fix:
(a) Compile it, and link it with your application as the last object
file in the link list. CAUTION: ensure that you have at least
*ONE* exit() call in your code, otherwise the version of exit()
in libC.a will be picked up. (Old-time Unix'ers will know why).
OR
(b) Replace the file in /usr/lib/libC.a:
# ar rv /usr/lib/libC.a exit.o
Be careful with the last: You may want to save the old libC.a
before doing this, in case anything goes wrong..
--
Shankar Unni E-Mail: shankar@sgi.com
Silicon Graphics Inc. Phone: +1-415-390-2072
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads