public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Creating C library implemented in C++
@ 2003-10-21 16:04 lrtaylor
  2003-10-21 17:43 ` Stuart F. Downing
  0 siblings, 1 reply; 4+ messages in thread
From: lrtaylor @ 2003-10-21 16:04 UTC (permalink / raw)
  To: sdowning, gcc-help

Stuart, 

If you declare your functions in an 'extern "C"' block and then compile
and link them with g++, I think you'd have the effect you are looking
for, and your exception handling problem should also be taken care of.
The 'extern "C"' block should disable the name mangling, allowing the
functions to be used from a C program and using their own C compiler.
Linking it with g++ will add all extra command line arguments needed to
enable support for stack unwinding, etc., necessary for exception
handling.

Cheers,
Lyle

-----Original Message-----
From: Stuart F. Downing [mailto:sdowning@fame.com] 
Sent: Tuesday, October 21, 2003 9:48 AM
To: gcc-help@gcc.gnu.org
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.

PROBLEM: Any exceptions thrown result in program termination, not
tranfer of control to the enclosing try/catch.  


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Creating C library implemented in C++
  2003-10-21 16:04 Creating C library implemented in C++ lrtaylor
@ 2003-10-21 17:43 ` Stuart F. Downing
  0 siblings, 0 replies; 4+ messages in thread
From: Stuart F. Downing @ 2003-10-21 17:43 UTC (permalink / raw)
  To: lrtaylor; +Cc: gcc-help

lrtaylor@micron.com writes:

> Stuart, 
> 
> If you declare your functions in an 'extern "C"' block and then compile
> and link them with g++, I think you'd have the effect you are looking
> for, and your exception handling problem should also be taken care of.
> The 'extern "C"' block should disable the name mangling, allowing the
> functions to be used from a C program and using their own C compiler.
> Linking it with g++ will add all extra command line arguments needed to
> enable support for stack unwinding, etc., necessary for exception
> handling.

The reason I used the gcc driver instead of g++ was that I wanted the
gcc libraries statically linked, and g++ overrode my attempts to link
statically.  It was a while back that I switched to the gcc driver, so
my recollection of the issues is getting a bit vague.  I'll retry with
g++ and see if I can get it to work the way I want.  

Thanks,
Stuart

> 
> Cheers,
> Lyle
> 
> -----Original Message-----
> From: Stuart F. Downing [mailto:sdowning@fame.com] 
> Sent: Tuesday, October 21, 2003 9:48 AM
> To: gcc-help@gcc.gnu.org
> 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.
> 
> PROBLEM: Any exceptions thrown result in program termination, not
> tranfer of control to the enclosing try/catch.  
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Creating C library implemented in C++
@ 2003-10-21 18:16 lrtaylor
  0 siblings, 0 replies; 4+ messages in thread
From: lrtaylor @ 2003-10-21 18:16 UTC (permalink / raw)
  To: sdowning; +Cc: gcc-help

If you place '-static' as the last argument on the link command line,
that should cause the "standard" libraries (libstdc++, etc.) to get
linked in statically.  Or you could specify "-nostdlib", which would
keep g++ from adding the libraries automatically.  You could then
explicitly link to the libraries the way you want.  I'm not sure if that
causes any other changes to be made to the linker command line that GCC
uses internally, though...

Cheers,
Lyle

-----Original Message-----
From: Stuart F. Downing [mailto:sdowning@fame.com] 

The reason I used the gcc driver instead of g++ was that I wanted the
gcc libraries statically linked, and g++ overrode my attempts to link
statically.  It was a while back that I switched to the gcc driver, so
my recollection of the issues is getting a bit vague.  I'll retry with
g++ and see if I can get it to work the way I want.  

Thanks,
Stuart

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Creating C library implemented in C++
@ 2003-10-21 15:48 Stuart F. Downing
  0 siblings, 0 replies; 4+ messages in thread
From: Stuart F. Downing @ 2003-10-21 15:48 UTC (permalink / raw)
  To: gcc-help

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-21 18:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-21 16:04 Creating C library implemented in C++ lrtaylor
2003-10-21 17:43 ` Stuart F. Downing
  -- strict thread matches above, loose matches on Subject: below --
2003-10-21 18:16 lrtaylor
2003-10-21 15:48 Stuart F. Downing

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).