具有zlib支持的交叉编译Python

时间:2020-08-26 09:05:58

标签: python arm cross-compiling zlib

我正在尝试通过zlib支持对python进行交叉编译。

我做了什么,正在做什么:

  • 下载的Python源代码(Python-3.6.5)
  • 从Python文件夹中编译的zlib:
#!/bin/sh

# Path to angstrom cross-compiler
CROSS_COMPILE=/home/angstrom/arm/bin

CC=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-gcc CXX=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-g++ AR=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-ar LD=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-ld \
        RANLIB=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-ranlib \
    ./configure \
    --prefix=$HOME/python \
    --enable-shared
  • 将已编译的zlib库文件复制到Angstrom编译器的位置,以确保找到它。
  • 配置Python:
#!/bin/sh

# Path to angstrom bin folder
CROSS_COMPILE=/home/angstrom/arm/bin

CC=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-gcc CXX=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-g++ AR=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-ar LD=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-ld \
        RANLIB=$CROSS_COMPILE/arm-angstrom-linux-gnueabi-ranlib \
    ./configure --host=arm-angstrom-linux --target=arm-angstrom-linux-gnueabi \
    --build=x86_64-linux-gnu --prefix=$HOME/python \
    READELF==arm-angstrom-linux-gnueabi-readelf \
    --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
    ac_cv_have_long_long_format=yes --enable-shared
  • 像讨论的here一样在“模块/设置”中激活zlib。
  • 进行安装并进行安装
#!/bin/sh

# Path to angstrom bin folder
CROSS_COMPILE=/home/toolchain/angstrom/arm/bin

make HOSTPYTHON=$HOME/python \
BLDSHARED="$CROSS_COMPILE/arm-angstrom-linux-gnueabi-gcc -shared" CROSS-COMPILE=arm-angstrom-linux-gnueabihf- \
CROSS_COMPILE_TARGET=yes HOSTARCH=arm-angstrom-linux BUILDARCH=arm-angstrom-linux-gnueabihf

make altinstall HOSTPYTHON=$HOME/python \
BLDSHARED="$CROSS_COMPILE/arm-angstrom-linux-gnueabi-gcc -shared" CROSS-COMPILE=arm-angstrom-linux-gnueabihf- \
CROSS_COMPILE_TARGET=yes HOSTARCH=arm-angstrom-linux BUILDARCH=arm-angstrom-linux-gnueabihf \
prefix=$HOME/python

make进程状态zlib的输出未编译:

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel
_dbm                  _gdbm                 _lzma
_sqlite3              _ssl                  _tkinter
readline              zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

将已编译的模块复制到arm设备,可以显示Python的工作原理,但没有zlib支持。

1 个答案:

答案 0 :(得分:0)

Python 将检测 setup.py 中的 zlib 和其他依赖项。在检测之前,它会在 CPPFLAGSLDFLAGS 中搜索有效的包含目录和库目录。因此,在配置 Python 时尝试设置 CPPFLAGSLDFLAGS,如下所示:

CC=blah CXX=blah AR=blah LD=blah RANLIB=blah \
CPPFLAGS="-I$HOME/python/include" LDFLAGS="-L$HOME/python/lib" \
    ./configure blahblah