C++ to C Wrapper using SWIG (for FLTK)
Asked Answered
B

1

14

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.

Blindfold answered 28/12, 2010 at 15:35 Comment(3)
Interesting, from what I can tell from the documentation, SWIG generates C wrappers for C++ code, it should be possible to use those directlyPlacatory
Thank you, but I can't find in documentation information on how to do that. I will continue searching...Blindfold
@Hasturkun: I think you are misinterpreting the documentation.Armalla
P
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.

Patrica answered 28/12, 2010 at 17:18 Comment(5)
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.Armalla
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!Blindfold
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.Blindfold
Yo can download SWIG with C backend from svn (swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd). It best compiled with mingw+msys (use automated installer: sourceforge.net/projects/mingw/files/…) with such commands: ./autogen.sh && ./configure && make. Use swig in such way: swig -c++ -c fltk13.iBlindfold
There was a gsoc2012 not yet finished but closer.Exasperate

© 2022 - 2024 — McMap. All rights reserved.