簡體   English   中英

使用Swig在python / c ++中編譯錯誤

[英]Compiling error with python/c++ using swig

我正在嘗試使用swig和安裝文件將C ++代碼與numpy包裝到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:Warnung:»swig_module«definiert,aber nicht verwendet

[-Wunused-variable]

錯誤:命令“ 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的行。 抱歉,我應該早考慮一下...

感謝您對頭文件的提示,這是該文件最后一行的錯字。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM