SWIG-PYTHON -> Problem in header file inclusion

abarun22 at gmail.com abarun22 at gmail.com
Fri Oct 19 16:51:36 CEST 2007


Hi
I am facing a problem while including a C header file in the SWIG
interface file.  However the problem does not occur when i directly
copy the contents of header file in the same place.

My interface file read as follows.
/*  interface file dep.i  */
%module dep
%{
#include "dep.h"
%}
%inline %{
extern int  ReadDep (char* fname, DONfic* don, int nb2, int nb4);
%}

And my header file consists of the structure DONfic as shown below.
/* Header file dep.h */
typedef struct _DONfic {
        int        nb_dep, nb_inc_dep, ncasec_dep;
        int        max_dep;
} DONfic;

>From python i tried to access the C structure as a python class as
shown below.
/* File pydep.py*/
>> import dep
>>.......
>> d = dep.DONfic()
Gives the following error message

Traceback (most recent call last):
  File "pydep.py", line 5, in ?
    d = dep.DONfic()
AttributeError: 'module' object has no attribute 'DONfic'
The problem is that i cannot get access to the structure if i directly
include the file "dep.h". On the other hand if i copy the contents of
the header file and paste it directly in to the header section of the
SWIG interface file it works.
It works for the following interface file .
%module dep
%{
typedef struct _DONfic {
        int        nb_dep, nb_inc_dep, ncasec_dep;
        int        max_dep;
} DONfic;
%}
%inline %{
extern int  ReadDep (char* fname, DONfic* don, int nb2, int nb4);
%}


I tried out lot of options and does n't seems to work. Any suggestions
or ideas are most welcome.




More information about the Python-list mailing list