我正在尝试使用distutils模块在Linux for Windows(mingw32)上交叉编译一个简单的SWIG Python扩展。
最终目标是为某些库编译Python包装器并能够在Windows上使用它。显然,我从最基本的例子开始,不幸的是它失败了。
这是我正在使用的文件:
example.c
/* File : example.c */
/* A global variable */
double Foo = 3.0;
/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
int g;
g = y;
while (x > 0) {
g = x;
x = y % x;
y = g;
}
return g;
}
example.i - SWIG接口文件
/* File : example.i */
%module example
%inline %{
extern int gcd(int x, int y);
extern double Foo;
%}
setup.朋友
# setup.py
import distutils
from distutils.core import setup, Extension
setup(name = "SWIG example",
version = "1.0",
ext_modules = [Extension("_example", ["example.i","example.c"])])
为了使用本机(Linux)gcc编译器进行编译,我正在调用:
python setup.py build
一切都像魅力一样!不幸的是,在尝试指定Windows目标时:
python setup.py build --compiler=mingw32
我收到错误说gcc无法识别-mdll开关:
running build
running build_ext
building '_example' extension
swigging example.i to example_wrap.c
swig -python -o example_wrap.c example.i
creating build
creating build/temp.linux-x86_64-2.7
gcc -mdll -O -Wall -I/home/jojek/anaconda/include/python2.7 -c example_wrap.c -o build/temp.linux-x86_64-2.7/example_wrap.o
gcc: error: unrecognized command line option ‘-mdll’
error: command 'gcc' failed with exit status 1
很公平,它很有道理,因为工具链无效。我确保在我的机器上安装了mingw32
。通过调用dpkg -L mingw32
我知道编译器位于/usr/bin/i586-mingw32msvc-gcc
。
我的下一步是用我的编译器的实际路径覆盖CC环境变量。当我再次尝试编译它时,我收到以下错误,缺少sys/select.h
头文件:
running build
running build_ext
building '_example' extension
swigging example.i to example_wrap.c
swig -python -o example_wrap.c example.i
creating build
creating build/temp.linux-x86_64-2.7
/usr/bin/i586-mingw32msvc-gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/jojek/anaconda/include/python2.7 -c example_wrap.c -o build/temp.linux-x86_64-2.7/example_wrap.o
example_wrap.c:1: warning: -fPIC ignored for target (all code is position independent)
In file included from /home/jojek/anaconda/include/python2.7/Python.h:58,
from example_wrap.c:125:
/home/jojek/anaconda/include/python2.7/pyport.h:351:24: error: sys/select.h: No such file or directory
error: command '/usr/bin/i586-mingw32msvc-gcc' failed with exit status 1
有谁知道如何管理这项任务?