This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Creating C library implemented in C++
- From: sdowning at fame dot com (Stuart F. Downing)
- To: gcc-help at gcc dot gnu dot org
- Date: 21 Oct 2003 11:48:05 -0400
- Subject: Creating C library implemented in C++
I am porting a C library to C++. The library is distributed in both
shared and static verstions. The resultant library must still be
callable from C clients.
This library used to use setjmp/longjmp for error recovery. I have
converted these to try/catch/throw clauses.
Clients of my library don't necessarily use gcc.
I used the gcc driver to partially link all my modules into a single
module. When I did this, I statically linked the resultant module
with -lgcc -lstdc++ -lgcc_eh. So clients don't need gcc or any gcc
shared libraries to use my library.
PROBLEM: Any exceptions thrown result in program termination, not
tranfer of control to the enclosing try/catch.
I can debug the code where the exception is thrown and see that
_Unwind_Find_FDE in unwind_dw2_fde.c returns NULL. I assume this is
because the normal exception handling frame initialization that would
occur in a simple program (in crtbegin.o?), has not occured before the
client calls the first API in my library. When _Unwind_Find_FDE
returns NULL, the exception code calls abort (eventually).
My library has init and cleanup routines that end users are expected
to call before/after calling any library routines. I could
theoretically call the necessary gcc init and cleanup functions in
these functions - if I knew what to call, and had some confidence it
would work. I'm also concerned that global constructors/destructors
are called.
Is there a straightforward approach to implmenting C libraries in C++
using gcc?
My gcc version info... (although I'd like whatever solution I find
to also work on HP-UX, AIX, Linux and mingw32 - naturally)
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/specs Configured
with: ../configure --disable-nls --with-ld=/usr/ccs/bin/ld
--with-as=/usr/ccs/bin/as Thread model: posix gcc version 3.2.2
--
Stuart Downing