Alex Rivera | Logout

Examples of C interfaces to C++ libraries?

Asked 2011-11-04T11:38:03.543
13

I'm in the process of writing a C interface to a C++ library, and I'm looking for some high-quality examples (or best practices).

So far this one seems pretty promising: http://czmq.zeromq.org/manual:czmq

Any other suggestions?

c++ c
Edit
Report

2 Answers

1

libzmq is a kind of weird case since the low-level C API was originally meant to look like POSIX sockets, and absolutely not object-oriented (we made it more consistent and organized over time). Meanwhile the actual library is in C++.

The C++-to-C interface is in libzmq/src/zmq.cpp, and consists of a bunch of simple C functions that call the 'real' C++ code.

CZMQ on the other hand aims for something more classy, providing a simple class model with constructors, destructors, containers, private properties, etc. Nothing radical but does turn C into a much more elegant language.

I'm not sure how well the CZMQ class approach would map to a C++ API unless that API was explicitly designed to be mapped.

Disclaimer: I'm the author of most of CZMQ.

answered 2012-11-21T07:57:01.917
0

I can suggest FTGL which is a C++ library providing a C interface. Here are two sample programs that achieve exactly the same thing:

Note also that FTGL uses the pImpl paradigm in order to achieve binary compatibility across versions. See here why it's good.

Disclaimer: I'm an FTGL contributor.

answered 2011-11-04T12:41:50.480

Your Answer