python交叉编译_交叉编译Python设置

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.

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.

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

^

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?

Environment setup

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

Configure Windows Python Run

./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/"

Configure Linux Python Run

./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/"

解决方案

Try to insert this into your Makefile:

CFLAGS+= \

-DHAVE_SSIZE_T \

-DPY_FORMAT_SIZE_T="l" \

-DPY_FORMAT_LONG_LONG="ll" \

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值