0

swigとセットアップファイルを使用して、numpyでc++コードをpythonにラップしようとしています。かなり単純なswigファイルとsetup.pyを作成しましたが、実行すると(Windows XPで)

python setup.py build -c mingw32

共有ライブラリのコンパイルが失敗します。理由がわからないので、誰かが私を正しい方向に向けてくれることを願っています。何が起こるか: setup-skript が swig を正常に実行し、ラップされた 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++

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: »extern« の前に初期化子が必要です

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

[-Wunused-変数]

エラー: コマンド 'gcc' が終了ステータス 1 で失敗しました

私の swig ファイルは次のようになります。

%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 行目:

    #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);
}

行 3059 は numpy/arrayobject.h を含む行です。すみません、もっと早く考えるべきでした…

4

1 に答える 1