#1230 Header include not in _wrap

java (79)
Adrian Roth

I'm evaluating Swig. Therefore I created an example.

Here's the header file SimpleMathClass.h

class SimpleMathClass {
virtual ~SimpleMathClass();

int add\(int a, int b\);
int subtract\(int a, int b\);


...and the implementation SimpleMathClass.cpp

#include "SimpleMathClass.h"

SimpleMathClass::SimpleMathClass() {
// TODO Auto-generated constructor stub


SimpleMathClass::~SimpleMathClass() {
// TODO Auto-generated destructor stub

int SimpleMathClass::add(int a, int b) {
return a + b;

int SimpleMathClass::subtract(int a, int b) {
return a - b;

...then I use the following command to generate the Java and C++ wrappers:
$ swig -java -c++ -package $PACKAGE -module _SimpleMathClass -outdir $OUTDIR SimpleMathClass.h

When creating the shared c++ library I get loads of error messages. The problem is that the generated SimpleMathClass_wrap.cxx does not include a reference (#include SimpleMathClass.h) to the header file. After adding this manually, everything works as expected.

Problem: The link (#include) to the header file should be added by the SWIG command itself.


  • Adrian Roth

    Adrian Roth - 2012-03-19

    I extended my example from above by adding another method (anotherMethod(std::map<int,int> myMap)) and extended the preprocessor directives of SimpleMathClass.h:

    #ifdef SWIG
    %include "std_map.i"
    %include "IMathClass.h"

    namespace std {
    %template(IntMap) map<int,int>;

    With this extension I additionally had to add the reference to <map>:
    #include "SimpleMathClass.h"
    #include <map>

    After adding this 2 lines everything works as expected! — SWIG is great ;-)

  • William Fulton

    William Fulton - 2012-03-19

    Newbie error - not a bug.

  • William Fulton

    William Fulton - 2012-03-19
    • status: open --> open-invalid
  • Adrian Roth

    Adrian Roth - 2012-03-19

    Can you point me to the right spot in the documentation?

    Thanks in Advance

  • William Fulton

    William Fulton - 2012-04-14
    • status: open-invalid --> closed-invalid

Log in to post a comment.