2013-10-16 52 views
0

我想用numpy使用swig和安裝文件將C++代碼包裝到python中。我創建了一個相當簡單痛飲文件和一個setup.py,但是當我運行(在Windows XP)使用swig編譯錯誤python/C++

python setup.py build -c mingw32 

編譯共享庫的失敗。我不知道爲什麼,所以希望有人能指出我正確的方向。 會發生什麼事情是這樣的: 設置skript運行,因爲它應該,幷包裹goldstein_wrap.cpp創建。然後MinGW的是所謂的,它失敗:

C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Programme\Python27\lib\site-packages\numpy\core\include -IC:\Programme\Python27\include -IC:\Programme\Python27\PC -c > goldstein_wrap.cpp -o build\temp.win32-2.7\Release\goldstein_wrap.o -static-libgcc -static-libstdc++

In file included from C:\Programme\Python27\lib\site-packages\numpy\core\include/numpy/ arrayobject.h:14:0,

  from goldstein_wrap.cpp:3059: 

C:\Programme\Python27\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:10:1:

Fehler: expected initializer before »extern«

goldstein_wrap.cpp:2954:25: Warnung: »swig_module« definiert, aber nicht verwendet

[-Wunused-variable]

error: command 'gcc' failed with exit status 1

我痛飲文件看起來像這樣:

%module goldstein 

%{ 
    #define SWIG_FILE_WITH_INIT 
    #include "goldstein.h" 
%} 

/*include numpy typemaps*/ 
%include "numpy.i" 

/*initialize module*/ 
%init %{ 
    import_array(); 
%} 

%rename(unwrap2d) phase_unwrapping_func; 

/* typemaps for the arrays*/ 
%apply (int DIM1,int DIM2,float* IN_ARRAY2) {(int ysize,int xsize,float* in)}; 
%apply (int DIM1,int DIM2,unsigned short* IN_ARRAY2) {(int y1,int x1,unsigned short* mask)}; 
%apply (int DIM1,int DIM2,float* INPLACE_ARRAY2) {(int y2,int x2,float* out), 
              (int y3,int x3,float* bcuts), 
              (int y4,int x4,float* res), 
              (int y5,int x5,float* diff)} 


%inline %{ 
void phase_unwrapping_func(int ysize,int xsize,float* in,int y1,int x1, 
       unsigned short* mask,int y2,int x2,float* out, int y3,int x3, 
       float* bcuts,int y4,int x4,float* res, int y5,int x5,float* diff) 
{ 
    phase_unwrapping(xsize, ysize, in, mask, out, bcuts, res, diff); 
} 
%} 

並給予真正的所有信息,我setup.py:

from distutils.core import setup, Extension 

import numpy 

try: 
    np_include = numpy.get_include() 
except AttributeError: 
    np_include = numpy.get_numpy_include() 

_goldstein = Extension('_goldstein', 
         ['goldstein.i','goldstein.cpp'], 
         include_dirs=[np_include], #include python dll 
         swig_opts=['-c++'], #enable c++ wrapping 
         extra_compile_args=["-static-libgcc", 
              "-static-libstdc++"], 
         ) 

setup(name='goldstein', 
     version='1.1', 
     description='Blubb', 
     author='Foo', 
     ext_modules = [_goldstein] 
    ) 

而且,根據需要,所提到的swig生成文件的行: 2950到2958行:

/* -------- TYPES TABLE (BEGIN) -------- */ 

#define SWIGTYPE_p_char swig_types[0] 
static swig_type_info *swig_types[2]; 
static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0}; 
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) 
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) 

/* -------- TYPES TABLE (END) -------- */ 

和線條3051到3060:3059

#define SWIG_FILE_WITH_INIT 
#include "goldstein.h" 


#ifndef SWIG_FILE_WITH_INIT 
# define NO_IMPORT_ARRAY 
#endif 
#include "stdio.h" 
#include <numpy/arrayobject.h> 


void phase_unwrapping_func(int ysize,int xsize,float* in,int y1,int x1, 
          unsigned short* mask,int y2,int x2,float* out, 
          int y3,int x3,float* bcuts,int y4,int x4,float* res, 
          int y5,int x5,float* diff) 
{ 
     phase_unwrapping(xsize, ysize, in, mask, out, bcuts, res, diff); 
} 

行是一個包括numpy的/ arrayobject.h。對不起,我應該早一點想過...

+0

我們需要看到SWIG生成的文件'goldstein_wrap.cpp',其中一些行導致行3059 – Oktalist

+0

當然,我添加了特定的行 – Dux

+0

編譯器似乎陷入了'stdio .h'文件。這應該是一個標準的C頭文件,但這將是不尋常的,但也許在包含路徑中有另一個相同的文件。否則,我會懷疑'goldstein.h'中有什麼錯誤。 – Oktalist

回答

0

感謝提示頭文件,它是該文件的最後一行中的拼寫錯誤。