Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(SWIG C++ to Python) warning 301: class keyword used, but not in C++ mode

Tags:

c++

python

swig

I am attempting to compile a C++ extension for python.

I have created an interface file foo.i which looks like this:

%module foo

%include "typemaps.i"                           // For pointers to primitive types
%include "std_string.i"                         // std::string mapping
%apply const std::string& {std::string* foo};   // data types containing std::string members

%{
#define SWIG_FILE_WITH_INIT
#include "../path/to/c++/header/files/foo_header.h"
%}

%apply double *OUTPUT { double *p, double *p2, double *p3 };
%apply double *OUTPUT { double *a1, double *a2, double *a3 };
%apply double *OUTPUT { double *a, double *b };

class FooBar
{
   /* 
      method signatures etc ...
   */
};

The warning is issued when the class keyword is encountered. Further on in the class declaration, a C++ keyword (bool) is encountered in one of the method signatures, and at which point SWIG barfs.

I can't see anything in the docs that states that (how?) SWIG should be informed that the files being parsed are C++ - as a matter of fact, IIRC, in the documentation, we are told that SWIG is able to deduce whether a file is C/C++ from the headers alone - so what's going on?

Incidentally, I am using SWIG Version 2.0.4

like image 898
Homunculus Reticulli Avatar asked Dec 23 '11 17:12

Homunculus Reticulli


1 Answers

You need to call SWIG with -c++ when you call it if you're using C++.

like image 176
2 revs Avatar answered Oct 11 '22 17:10

2 revs