Solution:

 

%insert("runtime")

%{

       #include "______.h"

%}

 

From: Charles Floyd [mailto:cfloyd@jht.com]
Sent: Wednesday, November 24, 2010 3:55 PM
To: swig-user@lists.sourceforge.net
Subject: [Swig-user] %extend generated code being placed before my includes (thus cant find ref classes)

 

my %extend generated code being placed before my includes which is causing undeclared ident compile errors. I provided two examples, one that doesn't work and the second that does. Also, I enabled features on the second example to see if that was causing the issue and it doesn't appear to be the case.

// ********************         MY STUFF (NOT WORKING)       **********************
//mymod.i
%module(directors="1") mymod

%feature("director");


%{
#include "mymod.h"
using namespace SDK;
%}
%include "mymod.h"

%extend SDK::Point2D {
        double getX() {
                return $self->p[0];
        }
        double getY() {
                return $self->p[1];
        }
}

//mymod.h
#include <SDK/Point2D.h>

//******************GENERATED******************************

//mymod_swig.cpp
...
#endif /* __cplusplus */

SWIGINTERN double SDK_Point2D_getX(SDK::Point2D *self){
                return self->p[0];
        }
SWIGINTERN double SDK_Point2D_getY(SDK::Point2D *self){
                return self->p[1];
        }

#include "mymod.h"
USING_PPI

/* ---------------------------------------------------
 * C++ director class methods
 * --------------------------------------------------- */

...

Which is clearly an issue. I need "mymod.h" to my before the generated extended methods for Point2D. However, if I create a simple project.

// *********************           EXAMPLE THAT WORKS      ***********************
//example.i (rip off of the nested swig example)
%module example

class Inner {
public:
        int var;
        Inner(int v = 0) : var(v) {}
};

%{
#include "outer.h"
%}
#include "outer.h"

%extend Outer {
        bool getX() {
                return true;
        }
}

// File outer.h
#include <stdio.h>

class Outer {
public:
        class Inner {
        public:
                int var;
                Inner(int v = 0) : var(v) {}
        };
        Inner getInner();
        void useInner(const Inner& inner);
};


// File outer.cpp
...


//******************GENERATED******************************
//example_swig.cpp

...

#include "outer.h"

SWIGINTERN bool Outer_getX(Outer *self){
                return true;
        }

typedef Outer::Inner Inner;


#ifdef __cplusplus
extern "C" {
#endif

...

It clearly creates the extension to the Outer class after the includes.

C. Floyd


Please consider the environment before printing this e-mail.

JHT CONFIDENTIALITY NOTICE: This email message, including any attachments,
may contain confidential information exclusively provided for intended
recipients or authorized representatives of the intended recipients. Any
dissemination of this e-mail by anyone other than an intended recipient or
authorized representatives of the intended recipients is strictly prohibited.
If you are not a named recipient or authorized representatives of the intended
recipients, you are prohibited from any further viewing of the e-mail or any
attachments or from making any use of the e-mail or attachments. If you believe
you have received this e-mail in error, notify the sender immediately and
permanently delete the e-mail, any attachments, and all copies thereof from any
drives or storage media and destroy any printouts of the e-mail or attachments.