[英]Compiling error with python/c++ using swig
I am trying to wrap c++ code to python with numpy using swig and a setup-file. 我正在尝试使用swig和安装文件将C ++代码与numpy包装到python中。 I created a rather simple swig file and a setup.py, but when I run (on Windows XP)
我创建了一个相当简单的swig文件和一个setup.py,但是当我运行时(在Windows XP上)
python setup.py build -c mingw32
compilation of the shared library fails. 共享库的编译失败。 I have no clue why, so hopefully someone can point me in the right direction.
我不知道为什么,所以希望有人能指出我正确的方向。 What happens is this: The setup-skript runs swig as it should, and a wrapped goldstein_wrap.cpp is created.
这是什么情况:setup-skript会按要求运行swig,并创建一个包装好的goldstein_wrap.cpp。 Then MinGW is called, and it fails:
然后调用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:\\ 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,
在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:
C:\\ Programme \\ Python27 \\ lib \\ site-packages \\ numpy \\ core \\ include / numpy / ndarrayobject.h:10:1:
Fehler: expected initializer before »extern«
Fehler:»extern«之前的预期初始化程序
goldstein_wrap.cpp:2954:25: Warnung: »swig_module« definiert, aber nicht verwendet
goldstein_wrap.cpp:2954:25:Warnung:»swig_module«definiert,aber nicht verwendet
[-Wunused-variable]
[-Wunused-variable]
error: command 'gcc' failed with exit status 1
错误:命令“ gcc”失败,退出状态为1
My swig file looks like this: 我的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);
}
%}
And to give really all information, my setup.py: 为了提供所有信息,我的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]
)
And, as demanded, the mentioned lines of the swig-generated file: Lines 2950 to 2958: 并且,根据需要,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) -------- */
And lines 3051 to 3060: 第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);
}
Line 3059 is the one including numpy/arrayobject.h. 3059行是包含numpy / arrayobject.h的行。 Sorry, I should have thought about that earlier...
抱歉,我应该早考虑一下...
感谢您对头文件的提示,这是该文件最后一行的错字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.