[英]How to cross-compile Python?
我有一个采用 Cortex A9 ARMv7 架构的 SoC。 我需要能够使用这个 SoC 在板上运行 python 脚本。 所以我需要为这个平台交叉编译Python。
SoC 具有 ARMv7 架构,因此我为 VirtualBox 中运行的 Ubuntu 20.04 安装了arm-linux-gnueabihf
交叉编译器。
我正在遵循此说明:
首先,我下载了Python 2.7.1源代码并将其解压缩到/home/user/python/Python-2.7.1
目录。
然后我从我遵循的说明下载了补丁。
然后我应用了补丁:
patch -p1 < python-2.7.1-cross-compile.patch
然后我为主机编译了一些工具:
./configure make python Parser/pgen mv python hostpython mv Parser/pgen Parser/hostpgen make distclean
然后我配置了 Python 进行交叉编译:
readonly CROSS_COMPILER=arm-linux-gnueabihf CC=${CROSS_COMPILER}-gcc \\ CXX=${CROSS_COMPILER}-g++ \\ AR=${CROSS_COMPILER}-ar \\ RANLIB=${CROSS_COMPILER}-ranlib \\ ./configure \\ --host=${CROSS_COMPILER} \\ --target=${CROSS_COMPILER} \\ --prefix=/python
然后我终于交叉编译它:
make \\ HOSTPYTHON=./hostpython \\ HOSTPGEN=./Parser/hostpgen \\ BLDSHARED="${CROSS_COMPILER}-gcc -shared" \\ CROSS_COMPILE=${CROSS_COMPILER}- \\ CROSS_COMPILE_TARGET=yes
但最终我得到了一个IndentationError
:
/usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: libpython2.7.a(posixmodule.o): in function `posix_tmpnam': /home/user/python/Python-2.7.1/./Modules/posixmodule.c:7346: warning: the use of `tmpnam_r' is dangerous, better use `mkstemp' /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: libpython2.7.a(posixmodule.o): in function `posix_tempnam': /home/user/python/Python-2.7.1/./Modules/posixmodule.c:7301: warning: the use of `tempnam' is dangerous, better use `mkstemp' File "./setup.py", line 316 self.announce('*** WARNING: renaming "%s" since importing it' ^ IndentationError: expected an indented block make: *** [Makefile:425: sharedmods] Error 1
我做错了什么以及如何解决这个问题?
似乎Python本身已成功编译和链接,因为在所有这些过程之后我在构建目录中获得了python
文件:
$ file python
python: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=1a757bca3295fe062ffbee5cf2d791eb36861524, for GNU/Linux 3.2.0, with debug_info, not stripped
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.