2015-07-20 105 views
3

我想編譯非常簡單的文件到python在Windows上,我的時間不好。使用swig編譯C++到python

的.i文件是testfile.i:

%module testfile 

%include "stl.i" 

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

int get_num() { 
     return 3; 
} 

的痛飲功能: {痛飲路徑} \ swig.exe -C++ -python testfile.i

這工作完全,我現在得到了testfile.py文件和testfile_wrap.cxx文件。 現在我明白,我需要將它編譯到庫(windows上的.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編譯/鏈接,但我得到了同樣的錯誤。我遵循教程,它仍然無法正常工作。

回答

1

解決方案:我的Python是64位,它沒有工作。更改爲python 32位,現在它正在工作(python 2.7.10)

+0

這將是因爲你的gcc正在編譯一個32位共享對象,這在Windows上很常見。有64位gcc版本可用於Windows,如果你有興趣:http://mingw-w64.org/doku.php –

+0

我實際上嘗試過它,同樣的問題。而我的視覺工作室也是64位,太奇怪了 – MyNick