Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWIG errors because of preprocessor directive

We have a vendor that has provided us a C++ library and headers, that I'm trying to wrap using SWIG. It appears that they are being too clever by a half with the preprocessor directives:

// top.h
#define DECLARE_WITH_COMMA(a) a,

and then

// foo.h
#include "top.h"

#define MY_TYPES(d) \
  d(One)   \
  d(Two)   \
  d(Three) \
  NumElems

enum MyTypes {
  MY_TYPES(DECLARE_WITH_COMMA)
};

Which is all a longwinded way of saying that when I try to run SWIG (version 2.0.4) on "foo.h", I get:

foo.h:12: Error: Syntax error in input(1).

So my question is what are my options here, given that I probably don't want to change the vendor-supplied headers?

like image 706
laslowh Avatar asked May 25 '12 19:05

laslowh


1 Answers

SWIG doesn't recurse into nested headers by default, so your .i file should look something like:

%module mymod

%{
#include "foo.h"
%}

%include "top.h"
%include "foo.h"

There is also a SWIG switch:

-includeall     - Follow all #include statements

but if you have system headers that may do more than you intend.

like image 176
Mark Tolonen Avatar answered Oct 27 '22 03:10

Mark Tolonen