一、python下载网址: http://www.python.org/ftp/python/
二、python的交叉编译依赖openssl ,openssl的下载网址: https://www.openssl.org/source/old/
三、编译:
1、交叉编译 openssl-1.0.2g
# /home/sw/openssh/openssl-1.0.2g # mkdir build # ./config --prefix=/home/sw/openssh/old/openssl-1.0.2g/build os/compiler:aarch64-linux-gnu-gcc -fPIC # make # make -i install
2、交叉编译python
# tar -xvf Python-2.7.7.tar.xz
# cd Python-2.7.7
# mkdir arm_build (存放交叉编译的信息)
# mkdir local_build (存放本地编译的信息)
# cd Python-2.7.7/
(1)首先本地编译pgen
# ./configure --prefix=/home/carrie/python/Python-2.7.7/local_build/ # make # make install # cp Parser/pgen arm_build/ # make clean
(2)交叉编译python
# vi Modules/_ctypes/libffi/fficonfig.py.in ffi_platforms = { 'AARCH64': ['src/aarch64/ffi.c', 'src/aarch64/sysv.S'], ##增加这一行 'MIPS_IRIX': ['src/mips/ffi.c', 'src/mips/o32.S', 'src/mips/n32.S'], # ./configure --prefix=/Python-2.7.7/arm_build/ --host=aarch64-linux-gnu --build=x86_64-linux-gnu CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar LD=aarch64-linux-gnu-ld ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no --disable-ipv6 # vim Makefile 77 LDFLAGS= -L/home/sw/openssh/old/openssl-1.0.2g/build/lib #找到LDFLAGS,在LDFLAGS后面增加这一串字符
# make
# make -i install
四、编译过程中遇到的错误:
(1)#./configure –prefix=/home/python/Python-2.7.7/build/ –host=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar –without-gcc
checking build system type… x86_64-unknown-linux-gnu
checking host system type… aarch64-unknown-linux-gnu
configure: error: Cross compiling required –host=HOST-TUPLE and –build=ARCH
原因:缺少–build的设置
解决方法:#./configure 后面加上 “–build=x86_64-linux-gnu “
(2)#./configure –prefix=/home/python/Python-2.7.7/build/ –host=aarch64-linux-gnu –build=x86_64-linux-gnu CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar –without-gcc
Fatal: You must get working getaddrinfo() function.
or you can specify “–disable-ipv6”.
解决方法:./configure 后面加上 “–disable-ipv6”
(3)# ./configure –prefix=/home/python/Python-2.7.7/build/ –host=aarch64-linux-gnu –build=x86_64-linux-gnu CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar –disable-ipv6
checking for /dev/ptmx… not set
configure: error: set ac_cv_file__dev_ptmx to yes/no in your CONFIG_SITE file when cross compiling
解决方法: ./configure后面加上 “ac_cv_file__dev_ptmx=no”
(4)#./configure –prefix=/home/python/Python-2.7.7/build/ –host=aarch64-linux-gnu –build=x86_64-linux-gnu CC=aarch64-linux-gnu-gcc AR=aarch64-linux-gnu-ar –disable-ipv6 ac_cv_file__dev_ptmx=no
checking for /dev/ptc… not set
configure: error: set ac_cv_file__dev_ptc to yes/no in your CONFIG_SITE file when cross compiling
解决方法:./configure后面加上 “ac_cv_file__dev_ptc=no”
(5)编译出错:
# make
make[1]: Leaving directory ‘/home/python/Python-2.7.7’
Parser/pgen ./Grammar/Grammar Include/graminit.h Python/graminit.c
Parser/pgen: 1: Parser/pgen: Syntax error: “(” unexpected
Makefile:616: recipe for target ‘Include/graminit.h’ failed
make: *** [Include/graminit.h] Error 2
解决方法:编译Parser/pgen :
# ./configure
# make python Parser/pgen
# cp Parser/pgen build/Parser/
(6)交叉编译产生的错误及解决方法:
#make
Failed to build these modules:
_bisect _codecs_cn _codecs_hk
_codecs_iso2022 _codecs_jp _codecs_kr
_codecs_tw _collections _csv
_ctypes _ctypes_test _elementtree
_functools _hashlib _heapq
_hotshot _io _json
_locale _lsprof _multibytecodec
_multiprocessing _random _socket
_ssl _struct _testcapi
array audioop binascii
cmath cPickle crypt
cStringIO datetime fcntl
future_builtins grp itertools
math mmap nis
operator parser pyexpat
resource select spwd
strop syslog termios
time unicodedata
running build_scripts
解决方法:
# vim Makefile
77 LDFLAGS= -L/home/sw/openssh/old/openssl-1.0.2g/build/lib #增加这一串字符