I need to generate wrapper to FLTK C++ classes to use it in pure C. I know, that SWIG can do that, and I know how to generate wrapper for C#, Python etc. But I do not know how to wrap C++ to C using SWIG. It's simple task, but I can't find the answer :) Please, help.
Asked
Active
Viewed 4,567 times
14
-
Interesting, from what I can tell from the documentation, SWIG generates C wrappers for C++ code, it should be possible to use those directly – Hasturkun Dec 28 '10 at 16:25
-
Thank you, but I can't find in documentation information on how to do that. I will continue searching... – Artem Dec 28 '10 at 17:18
-
@Hasturkun: I think you are misinterpreting the documentation. – Martin v. Löwis Dec 28 '10 at 17:38
1 Answers
6
I don't think SWIG supports generation of C wrappers out of the box. You always need to specify a target language. In 2008, there was a GSoC project to write a C backend, but that was apparently never completed/incorporated into SWIG.

Martin v. Löwis
- 124,830
- 17
- 198
- 235
-
I don't think this documentation is meant to be taken literal. Instead, this illustrates how the wrapper functions for each language look like. Instead of `new_list`, the Python generator (for example) generates `_wrap_new_List`; this becomes available to Python as `new_List`. `_wrap_new_List` does more than the documentation says, as it also needs to integrate with the Python VM. – Martin v. Löwis Dec 28 '10 at 17:36
-
Now I testing SWIG with C backend. Compiled It successfully with mingw, but got some errors while parsing FLTK includes (Such: FLTK13\FL\filename.h(60): Error: Syntax error in input(1).). I will report results... Thanks for idea! – Artem Dec 28 '10 at 18:22
-
I decided to go another way to solve my problem, but for problem described in question above, solution that Martin offered - the best solution, that can be found. Thank you again. – Artem Dec 28 '10 at 23:07
-
1Yo can download SWIG with C backend from svn (https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd/). It best compiled with mingw+msys (use automated installer: http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/) with such commands: ./autogen.sh && ./configure && make. Use swig in such way: `swig -c++ -c fltk13.i` – Artem Dec 28 '10 at 23:12
-
There was a [gsoc2012](https://github.com/swig/swig/tree/gsoc2012-c) not yet finished but closer. – xvan Apr 07 '16 at 04:55