What is a C wrapper to wrap C++ and how do you create one?
Quote:
> I was wondering how to create a C wrapper that interfaces with C++
> functions. How would you compile and link it? Thanks.
You need a header file which can be included by C, i.e. you have to use the
preprocessor to strip out anything which isn't C. Then you need to make sure
that C++ makes sure any definitions you create can be linked to compiled C
code.
You need something like this in your header file:
#ifdef __cplusplus
extern "C"
#endif
void fred (void);
This shields the C compiler from the non-C 'extern "C"' command, but lets C++
see it, and makes sure it produces a name for linking which will be
compatible with C. You can then write fred in C++ and call it from C.
--
Dan Ellis