Re: Accessing C++ from C
From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 01/08/04
- Next message: Karl Heinz Buchegger: "Re: I don't know what's wrong with my very simple code"
- Previous message: Stewart Gordon: "Re: Not STL newsgroup... Where?"
- In reply to: Evan Carew: "Re: Accessing C++ from C"
- Next in thread: Evan Carew: "Re: Accessing C++ from C"
- Reply: Evan Carew: "Re: Accessing C++ from C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 08 Jan 2004 17:43:32 +0100
Evan Carew wrote:
> 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.
Actually, there are C++ wrappers for the GNOME libs (e.g. gtkmm) and
some gnome programs are actually written in C++. There are also quite
some Un*x libs that are written in C++ and used from C programs, or
even plugin systems where the plugins and the main program are not
written in the same language, so glueing C code and C++ code together
isn't actually that uncommon.
> 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++.
Some developers want to use C rather than 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.
That's what I told you. Just look yourself at what happens. When trying
to link with gcc and with g++, add the -v command line option, and the
compiler will tell you what it does and what command line it passes to
the linker.
- Next message: Karl Heinz Buchegger: "Re: I don't know what's wrong with my very simple code"
- Previous message: Stewart Gordon: "Re: Not STL newsgroup... Where?"
- In reply to: Evan Carew: "Re: Accessing C++ from C"
- Next in thread: Evan Carew: "Re: Accessing C++ from C"
- Reply: Evan Carew: "Re: Accessing C++ from C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|