c++swig

How can I %include C++ headers in SWIG when they contain namespaces?


I have a SWIG file that includes a C++ header.

Swig file:

%module my_module

%{
#include "my_c_file.h"
%}

%include "my_c_file.h"

C++ header:

namespace my_namespace {
  void Foo();
}

The generated _wrap.cc file does not compile and contains odd c++ like:

namespace arg1 ;
namespace *argp1 ;

argp1 = (namespace *)jarg1; 

I suspect I'm missing some Swig command line option to get it to handle C++ namespaces correctly. What do I need to do?


Solution

  • It sounds like you are not telling swig that the source files are C++ files. Using swig -python -c++ has been working for us for a long time.

    Change your command line appropriately and things should work.