交叉编译Python设置 [英] Cross Compiling Python setup

查看:432
本文介绍了交叉编译Python设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Mingw-w64在Ubuntu 14.04上构建GObject-Introspection.我目前正在运行64位Linux,并尝试为32位Windows目标进行构建.

I am trying to build GObject-Introspection on Ubuntu 14.04 using Mingw-w64. I am currently running 64bit Linux and trying to build for a 32bit Windows target.

我的第一次尝试是使用Wine中安装的Python 2.7.8,但是,这没有用,因为Python的路径分隔符设置为'\'(以及'\'),而不是Linux的'/'.因此,我尝试在Ubuntu中使用Python 2.7.

My first attempt used Python 2.7.8 installed in Wine, however, this did not work because Python's path separator was set to '\' (well '\') instead of Linux's '/'. Due to this I tried using the Python 2.7 in Ubuntu.

使用Ubuntu提供的Python不会超出配置步骤. Config.log显示以下内容:

Using the Python provided by Ubuntu doesn't get past the configuration step. Config.log shows the following:

In file included from /usr/include/python2.7/Python.h:8:0,
                 from conftest.c:40:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch locatio#
 # error unknown multiarch location for pyconfig.h
   ^
In file included from /usr/include/python2.7/pyport.h:4:0,
                 from /usr/include/python2.7/Python.h:58,
                 from conftest.c:40:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch locatio#
 # error unknown multiarch location for pyconfig.h
   ^
In file included from /usr/include/python2.7/Python.h:58:0,
                 from conftest.c:40:
/usr/include/python2.7/pyport.h:241:9: error: #error "This platform's pyconfig.#
 #       error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
         ^
In file included from /usr/include/python2.7/pymath.h:4:0,
                 from /usr/include/python2.7/Python.h:77,
                 from conftest.c:40:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch locatio#
 # error unknown multiarch location for pyconfig.h
   ^

我了解到pyconfig.h定义的平台之间存在一些差异.我是否应该像操作系统那样将这些文件收集到单独的目录中(/usr/include/x86_64-linux-gnu/python2.7/pyconfig.h)?什么是Python的正确设置,以便我可以交叉编译GObject-Introspection?

I understand that there are some differences between the platforms that pyconfig.h defines. Should I be gathering these files into seperate directories like the OS seems to be doing (/usr/include/x86_64-linux-gnu/python2.7/pyconfig.h)? What is the correct setup for Python so that I can cross-compile GObject-Introspection?

export PREFIX=$CROSS_DIR/windows
export INSTALL_PREFIX=$PREFIX
export TOOLCHAIN_FILE=$PREFIX/toolchain_windows.cmake

export PLATFORM=WINDOWS

export HOST=i686-w64-mingw32
export BUILD=x86_64-linux-gnu

export COMPILER_INCLUDE_DIR=/usr/$HOST/include
export COMPILER_LIB_DIR=/usr/$HOST/lib
export MINGW_32_LIBS=/usr/lib/gcc/$HOST/4.8


export CFLAGS="-I$PREFIX/include -I$COMPILER_INCLUDE_DIR"
export CPPFLAGS="-I$PREFIX/include -I$COMPILER_INCLUDE_DIR"
export CXXFLAGS="-I$PREFIX/include -I$COMPILER_INCLUDE_DIR"
export LDFLAGS="-L$PREFIX/lib -L$COMPILER_LIB_DIR"
export XDG_DATA_DIRS="$PREFIX/share"

export LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/bin:$COMPILER_LIB_DIR
export LIBRARY_PATH=$PREFIX/lib:$PREFIX/bin:$COMPILER_LIB_DIR
export INCLUDE_PATH=$PREFIX/include:$COMPILER_INCLUDE_DIR
export C_INCLUDE_PATH=$PREFIX/include:$COMPILER_INCLUDE_DIR
export CPLUS_INCLUDE_PATH=$PREFIX/include:$COMPILER_INCLUDE_DIR


export CC=$HOST-gcc
export CXX=$HOST-g++
export LD=$HOST-ld
export RANLIB=$HOST-ranlib
export AR=$HOST-ar
export AS=$HOST-as
export STRIP=$HOST-strip


export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig

配置Windows Python运行

./configure --build="$BUILD" --host="$HOST" --prefix="$PREFIX" \
            PKG_CONFIG="$PREFIX/bin/pkg-config.exe" \
            PYTHON="$WINE_PYTHON_PATH/python.exe" \
            PYTHON_INCLUDES="-I$WINE_PYTHON_PATH/include" \
            PYTHON_LIBS="-L$WINE_PYTHON_PATH/libs -lpython27" \
            PYTHON_LIB_LOC="$WINE_PYTHON_PATH/Lib" \
            CFLAGS="$CFLAGS -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include/" \
            CPPFLAGS="$CPPFLAGS -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include/"

配置Linux Python运行

./configure --build="$BUILD" --host="$HOST" --prefix="$PREFIX" \
            PKG_CONFIG="$PREFIX/bin/pkg-config.exe" \
            PYTHON="/usr/bin/python2.7" \
            PYTHON_INCLUDES="-I/usr/include/python2.7/ -I/usr/include/x86_64-linux-gnu/python2.7/" \
            PYTHON_LIBS="-L/usr/lib/x86_64-linux-gnu/ -lpython2.7" \
            PYTHON_LIB_LOC="/usr/lib/python2.7/" \
            CFLAGS="$CFLAGS -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include/" \
            CPPFLAGS="$CPPFLAGS -I$PREFIX/include/glib-2.0 -I$PREFIX/lib/glib-2.0/include/"

推荐答案

尝试将其插入到Makefile中:

Try to insert this into your Makefile:

CFLAGS+=        \
                -DHAVE_SSIZE_T \
                -DPY_FORMAT_SIZE_T="l" \
                -DPY_FORMAT_LONG_LONG="ll" \

这篇关于交叉编译Python设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆