我一直在尝试在Windows 7下设置Python 2.7环境,以便我可以编译一个C++扩展用于Python。因为我是新手,所以我下载了一个简单的示例(此处),并使用了原始文件。我的路径中还有一个numpy.i文件。我已经安装了mingw(最新版本)和swig(v. 3.0.10),我的Python版本是2.7.9。我甚至使用这个环境编译了一个小的C++程序,没有问题。
但是,当尝试构建上述“简单”的Python扩展时,我总是得到以下输出,指示失败(我在Windows cmd.exe窗口中发出的命令作为下面第一行)。
如果需要其他代码,我很乐意发布它们,但是其他文件(
但是,当尝试构建上述“简单”的Python扩展时,我总是得到以下输出,指示失败(我在Windows cmd.exe窗口中发出的命令作为下面第一行)。
python setup.py build -c=mingw32
running build
running build_ext
building '_simple' extension
swigging simple.i to simple_wrap.c
C:\swigwin\swigwin-3.0.10\swig.exe -python -o simple_wrap.c simple.i
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\lib\site-packages\numpy\core\include -I. -IC:\Python27\include -IC:\Python27\PC -c simple.cc -o build\temp.win32-2.7\Release\simple.o
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\lib\sitepackages\numpy\core\include -I. -IC:\Python27\include -IC:\Python27\PC -c simple_wrap.c -o build\temp.win32-2.7\Release\simple_wrap.o
writing build\temp.win32-2.7\Release\_simple.def
C:\MinGW\bin\g++.exe -shared -s build\temp.win32-2.7\Release\simple.o build\temp.win32-2.7\Release\simple_wrap.o build\temp.win32-2.7\Release\_simple.def -LC:\Python27\libs -LC:\Python27\PCbuild -lpython27 -lmsvcr90 -o build\lib.win32-2.7\_simple.pyd
build\temp.win32-2.7\Release\simple_wrap.o:simple_wrap.c:(.text+0xce5): undefined reference to `create_list'
build\temp.win32-2.7\Release\simple_wrap.o:simple_wrap.c:(.text+0x170d): undefined reference to `dot'
collect2.exe: error: ld returned 1 exit status
error: command 'C:\\MinGW\\bin\\g++.exe' failed with exit status 1
我有一种可怕的感觉,觉得我可能错过了非常简单的东西,但在另一个Cygwin环境中,我已经成功编译了这些相同的文件,并且没有任何问题(是的,我希望能够在一个非Cygwin的环境中执行此操作)。
我不想用太多代码来描述这个问题,但为了参考,这里是我正在使用的simple.i
和setup.py
文件。
simple.i:
%module simple
%{
#define SWIG_FILE_WITH_INIT
#include "simple.h"
%}
%include "numpy.i"
%init %{
import_array();
%}
%apply (int DIM1, double* INPLACE_ARRAY1) {(int n0, double *a0)};
%apply (int DIM1, double* IN_ARRAY1) {(int n, double *a), (int m, double *b)};
%apply (int DIM1, double* ARGOUT_ARRAY1) {(int size, double *arr)};
%include "simple.h"
setup.py:
from distutils.core import setup, Extension
import numpy
import os
os.environ['CC'] = 'g++';
setup(name='matt_simple_test', version='1.0', ext_modules =[Extension('_simple',['simple.cc', 'simple.i'], include_dirs = [numpy.get_include(),'.'])])
如果需要其他代码,我很乐意发布它们,但是其他文件(
simple.cc
和simple.h
)均从此处直接使用。所以问题是:有人能指导我如何纠正这个错误吗?