编译c++;使用swig创建python

编译c++;使用swig创建python,python,c++,gcc,Python,C++,Gcc,我正试图在windows上将非常简单的文件编译成python,但我过得很不愉快 .i文件是testfile.i: %module testfile %include "stl.i" %{ int get_num() { return 3; } %} int get_num() { return 3; } swig功能: {swig path}\swig.exe-c++-python testfile.i 这非常有效,我现在得到了te

我正试图在windows上将非常简单的文件编译成python,但我过得很不愉快

.i文件是testfile.i:

%module testfile

%include "stl.i"

%{  
    int get_num() {
        return 3;
    }
%}  

int get_num() {
        return 3;
}
swig功能: {swig path}\swig.exe-c++-python testfile.i

这非常有效,我现在得到了testfile.py文件和testfile_wrap.cxx文件。 现在我明白了,我需要将它编译成库(.pyd)。我试过:

{gcc path}\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和compile/link,但我得到了相同的错误。我遵循了教程,但仍然不起作用。

解决方案:我的python是64位的,但不起作用。更改为python 32位,现在可以使用了(python 2.7.10)

这是因为您的gcc正在编译一个32位共享对象,这在windows上非常常见。如果你感兴趣的话,有64位gcc版本可用于windows:我确实试过了,同样的问题。我的visual studio也是64位的,很奇怪