1.本文链接地址
http://blog.csdn.net/lz_obj/article/details/52620276
2.环境
linux系统版本:Ubuntu 10.04
交叉编译工具:arm-linux-gcc4.5.2
嵌入式linux内核版本:Linux 2.6
3.操作步骤
(1)下载源码包Python-2.7.3.tgz和补丁Python-2.7.3-xcompile.patch,https://www.python.org/download/releases/2.7.3/
(2)将这两个文件放入/home/中,解压压缩包tar -xvzf Python-2.7.3.tgz,把补丁移动到Python-2.7.3/中,mv Python-2.7.3-xcompile.patch Python-2.7.3/,进入解压后的文件夹中cd Python-2.7.3
(3) 运行配置文件./configure
(4)make python Parser/pgen
(5)相应文件改名mv python hostpython,mv Parser/pgen Parser/hostpgen
(6)清理操作 make distclean
(7)打补丁patch -p1 < Python-2.7.3-xcompile.patch
(8)设置参数
CC=arm-none-linux-gnueabi-gcc
CXX=arm-none-linux-gnueabi-g++
AR=arm-none-linux-gnueabi-ar
RANLIB=arm-none-linux-gnueabi-ranlib
/* 此处设置根据个人情况,可与9运行配置文件一并执行 */
(9)修改setup.py
/*
说明:此处涉及python 调用sqlite3接口 参考 http://www.cnblogs.com/hit-python/articles/4081673.html 详细操作可以查看这篇文章,写的很详细,
我的sqlite3(arm linux)是之前编译好的,整个文件夹(包括bin/ lib/ ...),路径为/home/sqlite3_armlinux
*/
做如下修改
修改为:sqlite_inc_paths = ['/home/sqlite3_armlinux' + '/include' ]
sqlite_inc_paths = ['/home/sqlite3_armlinux' + '/include' ]
修改为:sqlite_inc_paths = ['/home/sqlite3_armlinux' + '/lib' ]
sqlite_inc_paths = ['/home/sqlite3_armlinux' + '/lib' ]
保存setup.py修改,运行配置文件 ./configure--host=arm-none-linux-gnueabi --prefix=/python
(10)make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgenBLDSHARED="arm-none-linux-gnueabi-gcc -shared"CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes
(11)make install HOSTPYTHON=./hostpython BLDSHARED="arm-none-linux-gnueabi-gcc-shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yesprefix=/home/Python-2.7.3/_install
/* 10.11此处一些设置根据个人情况 */
(12)将_install文件夹移动到开发板中
4.运行截图
5.参考资料
http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
http://www.cnx-software.com/2011/02/04/cross-compiling-python-for-mips-and-arm-platforms/
http://www.cnblogs.com/hit-python/articles/4081673.html