jbcoe
jbcoe

Reputation: 3921

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?

Upvotes: 1

Views: 664

Answers (2)

BHANU PRAKASH
BHANU PRAKASH

Reputation: 1

Please change your swig file to below, it will work

%module my_module
%{
#include "my_c_file.h"
using namespace my_namespace;
%}

%include "my_c_file.h"
using namespace my_namespace;

Upvotes: 0

R Sahu
R Sahu

Reputation: 206667

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.

Upvotes: 2

Related Questions