문제

I have a code as mentioned following ..

File : a.h

#include <stdio.h>

#ifdef ALLOW
int check(int n);
#endif 

SWIG: test.i

%module test
%{
  #include "a.h"
%}

%include "a.h"

CMD: swig -python test.i

this is generating a _test.so , when i am importing this library to python this is not displaying check function defined.

In Make I could have used -D option, say gcc -DALLOW a.c.

How can I achieve the same using SWIG

도움이 되었습니까?

해결책

As easy as it looks - swig -DALLOW -python test.i.

다른 팁

You can define preprocessor macros within the SWIG interface itself (i.e. inside the .i file).

So in your case you might want to do:

%module test
%{
  #include "a.h"
%}

#define ALLOW
%include "a.h"

That's enough to make SWIG itself "see inside" the #ifdef, but if you want to have ALLOW defined within the generated warpper code as well you'd want to add:

%module test
%{
  #define ALLOW
  #include "a.h"
%}

#define ALLOW    
%include "a.h"

because the contents of the %{ ... %} are passed straight through to that generated code whereas the plain #define only influences how SWIG itself sees the file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top