Re: Linking a C++ library to a C program.





CBFalconer wrote:
> Malcolm wrote:
> > "a2x" <add_aaron_2_x@xxxxxxxxxxx> wrote
> >>
> >> I am writing a C program which interfaces with a C++ library. The
> >> C++ library works fine with C. I was wondering if I need to use a
> >> C++ compiler (g++ in my case) to compile the C program or can I
> >> use a C compiler (gcc).
> >
> > If you want to call a function written in C++ from a C file your
> > best bet is to write the C code in the common subset of the two
> > languages and run it through a C++ compiler. The alternative is to
> > mess about with C++ name mangling and linkage conventions.
>
> For which alternative, AFAICT, there exists nothing even remotely
> resembling a standard, so that everything is totally non-portable.


Correct, but there is a C++ standard way to specify C-style linkage
(extern "C"). That prevents you from calling overloaded functions from
the C module, of course.

Whether a C object file can actually be linked with a C++ object file
or library is still implementation dependent. In practice it works
pretty well.

All of this should be discussed on comp.lang.c++, not here.



Brian

.



Relevant Pages

  • Re: Porting C software
    ... Is there a description anywhere of a "common subset" of C recognized ... It's called "the ISO C Standard" or, more formally, ISO/IEC 9899. ... Just about any C compiler you are likely to come across conforms to the ... implementation (say, gcc), and using this as a general reference ...
    (comp.lang.c)
  • Re: Requesting advice how to clean up C code for validating string represents integer
    ... GNU C is the C-like language accepted by gcc. ... violate the C standard. ... that you get the GNU C version of each library rather than the ANSI ...
    (comp.lang.c)
  • Re: [OT] lcc first experience
    ... GCC does embrace-and-extend? ... affect the behaviour of a strictly conforming program. ... Of course if implementations are called "lcc-win" you will start ranting ... making them 100% compatible with the C standard. ...
    (comp.lang.c)
  • Re: KEil bought by ARM
    ... >> against and that a user of gcc can add tests to. ... > tests demonstrate conformance to a recognized C standard like C89 ... and possibly with some extensions. ... > were renumbered and became clauses in the ISO standard. ...
    (comp.arch.embedded)
  • Re: Variable declaration - Is this valid in standard C?
    ... YES it is valid in standard C!!!! ... doesn't have a conforming C90 compiler (ignoring minor bugs, ... are in C99 but not in C90. ... That's what the gcc project's own web site says, ...
    (comp.lang.c)