Re: Accessing C++ from C
From: Evan Carew (tempcarew_at_pobox.com)
Date: 01/08/04
- Next message: Kirk Bevins: "Re: instances of my student class help!!"
- Previous message: Peter van Merkerk: "Re: Not STL newsgroup... Where?"
- In reply to: Rolf Magnus: "Re: Accessing C++ from C"
- Next in thread: Rolf Magnus: "Re: Accessing C++ from C"
- Reply: Rolf Magnus: "Re: Accessing C++ from C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 08 Jan 2004 09:07:48 -0500
Rolf, (and all others who replied with advice of varying degrees of
usefullness)
Thanks for your replies. While I generally don't like people who answer
their own questions, I have a feeling that this question is important
enough to the C++ and C community that it needs to be answered. I say
this because if C developers (or C++ developers) don't have a way to
gradually migrate their legacy code (C) to C++ then we will continue in
our current state of affairs we are in today where people like the
developers of GNOME continue to develop in C. With this technique,
someone could refactor their libraries in C++ and provide a C wrapper
for those still using legacy techniques, while newer developers could go
on to use C++.
Yesterday, I sent a message to the author of C/C++ Users Journal article
I mentioned in my query & he replied with the answer last night. It
turns out to be rather easy. The deal is that while the C compiler is
more than happy to compile the legacy code, and the C++ compiler
likewise happy to compile the wrapper code, the C linker simply wont
link the program. The strange fix is to compile the legacy code with
the C compiler (without linking), then link with g++. Voila, you have a
C front end to C++ library code.
So now, whenever I talk to some C jock who swears there is no way for C
to converse with C++, I'll simply point them to my interface code.
P.S.
If you are interested in a working swample project, I can send you a
gziped tar file which you can compile yourself.
Evan
Rolf Magnus wrote:
> Evan Carew wrote:
>
>
[snip]
>
>
> This is actually off-topic here, and should be asked in gnu.gcc.help or
> gnu.g++.help, but anyway, you need to use g++ for linking if your
> program contains c++ code.
>
- Next message: Kirk Bevins: "Re: instances of my student class help!!"
- Previous message: Peter van Merkerk: "Re: Not STL newsgroup... Where?"
- In reply to: Rolf Magnus: "Re: Accessing C++ from C"
- Next in thread: Rolf Magnus: "Re: Accessing C++ from C"
- Reply: Rolf Magnus: "Re: Accessing C++ from C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|