Re: Using C with C++ shared libraries


Subject: Re: Using C with C++ shared libraries
From: Paul J. Lucas (pjl@barefooters.org)
Date: Mon Jul 10 2000 - 16:31:56 MDT


On Mon, 10 Jul 2000, William K. Gibson wrote:

> This may be off topic for the group but...

        *May* be? It *is* off topic. comp.lang.c++ would be better.

> I know that to get C functions to work in a C++ program you must define them
> in the header file with the call:
>
> extern "C" { }
>
> Is there a similar trick that must be used to do the opposite?

        It's the same exact "trick" ("language feature" actually; it's
        not a "trick" since it was added to the langauge for expressly
        the purpose of cross-language linking), i.e., your C++
        library's functions must be declared extern "C", i.e., have C
        linkage.

        Naturally, the library can not use any C++ feature as part of
        its C API including bool, constructors, function overloading,
        default argument values, pass or return by reference, etc.

        - Paul



This archive was generated by hypermail 2a24 : Mon Jul 10 2000 - 16:34:47 MDT