Re: Wrapping C++ with C

From: Basile Starynkevitch [news] (basile-news_at_starynkevitch.net)
Date: 09/12/04


Date: Sun, 12 Sep 2004 11:34:58 +0000 (UTC)

On 2004-09-12, Roger Leigh <${roger}@invalid.whinlatter.uklinux.net.invalid> wrote:
> For several reasons, I'd like to make use of C++ features such as
> templated functions and STL lists and maps in a C shared library.
> However, from the outside I'd like it to appear as a regular C library
> with a C API and not requiring a C++ compiler for linking. Is this
> possible? [....]

> I believe all I need to do is write the code as C++ code with the C
> wrapper functions declared as extern "C". Is this correct?

If your library needs to run code (e.g. called by constructors of
static data) before main, it probably need some special (constructor)
ELF section, and I believe this might be C++ specific (and maybe
requires a C++ link).

You should check that no constructors are called by your
library. Essentially, if it has no global data, it should help.

But I never worked on such stuff, so I probably forgot other issues.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Faïencerie, 92340 Bourg La Reine, France


Relevant Pages

  • Re: ANN: Simple components v 1.3
    ... Actually here comes the motivation for maps from. ... Some time ago I posted a proposal for proper constructors, ... That could help to solve the problem of creating unconstrained objects ... exactly same discriminants / bounds as Key_Type. ...
    (comp.lang.ada)
  • consumption
    ... in the initializers and the constructors. ... never reset static data". ...
    (comp.lang.java.programmer)