【发布时间】:2020-12-15 03:25:28
【问题描述】:
我有一个采用 Cortex A9 ARMv7 架构的 SoC。我需要能够使用这个 SoC 在板上运行 python 脚本。所以我需要为这个平台交叉编译Python。
该 SoC 具有 ARMv7 架构,因此我为在 VirtualBox 中运行的 Ubuntu 20.04 安装了 arm-linux-gnueabihf 交叉编译器。
我正在关注this 指令:
-
首先我下载了Python 2.7.1 源并将其解压缩到
/home/user/python/Python-2.7.1目录。 -
然后我根据我遵循的说明下载了patch。
-
然后我已经应用了补丁:
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
【问题讨论】:
标签: python linux python-2.7 cross-compiling embedded-linux