我正在尝试在 Windows 上将非常简单的文件编译为 python,但我遇到了麻烦。
.i 文件是 testfile.i:
%module testfile
%include "stl.i"
%{
int get_num() {
return 3;
}
%}
int get_num() {
return 3;
}
swig函数: {swig 路径}\swig.exe -c++ -python testfile.i
这非常有效,我现在得到了 testfile.py 文件和 testfile_wrap.cxx 文件。 现在我明白我需要将其编译为库(Windows 上的 .pyd)。我试过:
{gcc 路径}\gcc.exe -fPIC -shared testfile_wrap.cxx -o testfile_wrap.pyd -L。 -LC:\Python27\libs\-lpython27 -IC:\python27\include.
这是问题所在,我遇到了很多这样的错误:
C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc00): undefined reference to `__imp_PyExc_MemoryError'
C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc13): undefined reference to `__imp_PyExc_IOError'
C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc26): undefined reference to `__imp_PyExc_RuntimeError'
C:\Users\itay\AppData\Local\Temp\ccANsNeU.o:testfile_wrap.cxx:(.text+0xc39): undefined reference to `__imp_PyExc_IndexError'
它一直在继续。
我做错了什么?
谢谢你的帮助
更新: 我设法使用 visual studio 2013 调用 swig 和编译/链接,但我得到了同样的错误。我按照教程进行操作,但仍然无法正常工作。
最佳答案
解决方案:我的 python 是 64 位的,它不工作。更改为 python 32 位,现在它正在工作(python 2.7.10)
关于python - 使用 swig 将 c++ 编译为 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31524867/