As easy as it looks - swig -DALLOW -python test.i
.
How to use restricted Code through SWIG
문제
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
해결책
다른 팁
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.