Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate C wrappers over C++ API using SWIG? [duplicate]

Tags:

c++

c

swig

I would like to generate C wrappers over some C++ API using SWIG.

From the SWIG documentation SWIG and C++:

6.2 Approach

To wrap C++, SWIG uses a layered approach to code generation. At the lowest level, SWIG generates a collection of procedural ANSI-C style wrappers. These wrappers take care of basic type conversion, type checking, error handling, and other low-level details of the C++ >binding. These wrappers are also sufficient to bind C++ into any target language that supports built-in procedures. In some sense, you might view this layer of wrapping as providing a C library interface to C++.

However, I don't see any option to do just that, without generating code for using the API in a language like Python, Ruby, etc. How can I get just the C wrappers?

like image 667
piokuc Avatar asked Nov 28 '11 23:11

piokuc


1 Answers

Although the main branch of SWIG cannot generate C wrappers for C++ API (the SWIG documentation quoted in the question is a bit misleading), there is a SWIG branch created during Google Summer of Code 2008 and available at https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd/ which does just that. I have found the answer here: C++ to C Wrapper using SWIG (for FLTK)

like image 184
piokuc Avatar answered Nov 07 '22 15:11

piokuc