【发布时间】:2021-04-07 23:27:59
【问题描述】:
我尝试运行 swig python 教程无济于事,我检查了许多类似的问题,但没有一个能解决我的问题,我正在使用
windows *,64 位
SWIG 版本 4.0.2
使用 i686-w64-mingw32-g++ [i686-w64-mingw32] 编译
配置选项:+pcre
该示例特别处理用 C 编写的 gcd 函数;
/* File : example.c */
/* A global variable */
double Foo = 3.0;
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}
/* File: example.i */
%module example
extern int gcd(int x, int y);
extern double Foo;
我跑了swig -python example.i
但每当我运行gcc -c -fpic example.c -IC:\Users\Moses\anaconda3\include
example_wrap.c: In function '_wrap_gcd':
example_wrap.c:2886:17: warning: implicit declaration of function 'gcd'; did you mean 'gcvt'? [-Wimplicit-function-decla
ration]
result = (int)gcd(arg1,arg2);
^~~
gcvt
example_wrap.c: In function 'Swig_var_Foo_set':
example_wrap.c:2901:5: error: 'Foo' undeclared (first use in this function)
Foo = (double)(val);
^~~
example_wrap.c:2901:5: note: each undeclared identifier is reported only once for each function it appears in
example_wrap.c: In function 'Swig_var_Foo_get':
example_wrap.c:2912:37: error: 'Foo' undeclared (first use in this function)
pyobj = SWIG_From_double((double)(Foo));
我只得到了 example.o 文件,而 example_wrap.o 文件丢失了,几乎肯定是因为错误,我还是尝试用ld -shared example.o /c/users/moses/Anaconda3/python37.dll /c/Windows/System32/msvcr120.dll -o _example.pyd 编译它
但是在尝试导入 example.py 文件时,我收到以下错误:
Traceback (most recent call last):
File "C:\Users\moses\cGraphy.py", line 1, in <module>
import example
File "C:/Users/moses/example.py", line 15, in <module>
import _example
ImportError: dynamic module does not define module export function (PyInit__example)
任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: c python-3.x gcc swig