交叉编译工具链

公开版本使用可以参考这篇博文:一次搞定 Arm Linux 交叉编译
定制版本一般配置文件比较齐全,一键配置:

  1. 将交叉编译工具链文件夹放到对应目录(有的工具链存放目录已写入配置文件,如/opt/,更改存放文件夹可能导致无法使用)
  2. 进入交叉编译工具链,source environment-xxxx
  3. 查看交叉编译工具链是否设置成功:
    arm-xxx-xxx-gcc -v
    arm-xxx-xxx-g++ -v

交叉编译python

  1. 下载python源码: Python
  2. 解压源码:tar -xvf Python-3.10.4.tar.xz
  3. 进入文件夹:cd Python-3.10.4
  4. 先切换到python3.10环境下,或者在本地编译python(./configure ; make),同时创建软连接将运行python链接到本地编译python(ln -s ./python /xx/bin/python),否则直接交叉编译python会报错(checking for python interpreter for cross build… configure: error: python3.10 interpreter not found)
  5. 交叉编译:./configure --prefix=pwd/build --host=arm-xxx-xx --build=x86_64-linux-gnu
  6. 编译报错:configure: error: set ac_cv_file__dev_ptmx(ac_cv_file__dev_ptc) to yes/no in your CONFIG_SITE file when cross compiling (解决方案:进入部署的arm平台,进入dev文件夹,查看是否有ptmx/ptc文件,有则设置yes否则设置no)
  7. 最终编译命令:

./configure --prefix=pwd/build --host=arm-xxx-xxx --build=x86_64-linux-gnu ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no

make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=“arm-xxx-xxx-gcc -shared” CROSS_COMPLIE=arm-xxx-xxx- CROSS_COMPLIE_TARGET=yes HOSTARCH=arm-xxx-xxx BUILDARCH=x86_64-linux-gnu -j2

make install HOSTPYTHON=./hostpython BLDSHARED=“arm-xxx-xxx-gcc -shared” CROSS_COMPILE=arm-xxx-xxx- CROSS_COMPILE_TARGET=yes prefix=$PWD/mybuild

  1. 将编译好的文件拷贝到arm设备上:

adb push ./Python-3.10.4 /xxx/test/

  1. 进入arm设备对应目录/xxx/test/Python-3.10.4/bin/,查看python:

./python3 --version
./python3

  1. 可以建立软链接,链接到新编译的python

ln -s ./python3 /usr/bin/python3

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐