---
# System prepended metadata

title: Python 3.X交叉編譯方法

---

Python 3.X交叉編譯方法
===
本身使用python 3.9.7 ,ubuntu 16.04
參考:https://www.csdn.net/tags/MtzaYgzsMDY2ODItYmxvZwO0O0OO0O0O.html

0.下載、解壓縮Python
```javascript=
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tar.xz
tar Jxvf Python3.9.7.tar.xz
```
1.先編譯 x86版本
```javascript=
cd Python3.9.7
mkdir bin
cd bin

../configure -prefix=`pwd`/install --enable-shared CFLAGS=-fPIC

make -j8
make install
```
2.設定交叉編譯環境
```javascript=
source /opt/fsl-imx-wayland/4.14-sumo/environment-setup-aarch64-poky-linux
export ARCH=arm64
unset LDFLAGS
echo $LDFLAGS
echo $ARCH
echo $CROSS_COMPILE

#路徑"/home/chris/workspace/mipc-master/Python-3.9.7"
#是我自己的路徑，請自行更改成自己編譯路徑

export PATH=/home/chris/workspace/mipc-master/Python-3.9.7/bin/install/bin:$PATH
export LD_LIBRARY_PATH=/home/chris/workspace/mipc-master/Python-3.9.7/bin/install/lib/
```
3.再編譯 arm64
```javascript=
cd ..
mkdir bin_aarch64
cd bin_aarch64

../configure --host=aarch64-poky-linux --build=x86 --enable-shared CFLAGS=-fPIC --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no

make -j8
make DESTDIR=`pwd`/install install
#完成後會在目前資料夾底下的install裡面
```

在/etc/rc.local加上 export LD_LIBRARY_PATH=/usr/local/lib/