2009年2月22日星期日

在android上编译运行python程序

Hi,

I have cross-compiled python 2.5 for ARM and copied it into android
emulator (see instructions below). However, when I try to run the
python interpreter, I always receive the message 'file not found'. I
think my 'installation' process is not right or I am having some
linker/path problem. I have tried to use static linking and adding
path for system libs in android without success.


Could anyone help me with this issue ? Instruction for compiling
python are below.
It is a modified version of compiling instructions found in 5.1, 5.2
and 5.3 (see references at the end).


0) Downloading arm compiler


I am using an ARM GNU/Linux toolchain, downloaded from:
http://www.codesourcery.com/gnu_toolchains/arm/download.html


I have installed the toolchain in:
/home/marcelo/toolchain/


1) Downloading sources and applying patches (see reference 5.1 at the
end)


mkdir ~/temp
cd ~/temp
wget http://www.python.org/ftp/python/2.5/Python-2.5.tar.bz2
wget http://whatschrisdoing.com/~lambacck/Python2.5_xcompile.patch
tar xvjf Python-2.5.tar.bz2
cd Python-2.5/
patch -p1 < ../python/Python2.5_xcompile.patch


2) Compiling python. There are some tricks for cross-compiling (see
references).
Change paths when necessary (like /home/marcelo or compiler path). gcc
-v can
provide you the value for --build parameter.


./configure
make python Parser/pgen
mv python hostpython
mv Parser/pgen Parser/hostpgen
make distclean


export PATH=/home/marcelo/toolchain/arm-2007q3/bin/:$PATH


make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-
none-linux-gnueabi-gcc -static" CROSS_COMPILE=yes


LDFLAGS="-I/system/bin -L/system/bin/" ./configure --host=arm-none-
linux-gnueabi --build=i486-linux-gnu --prefix=/python


make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-
none-linux-gnueabi-gcc -static" CROSS_COMPILE=yes


3) Local install (take care of paths)


make install HOSTPYTHON=./hostpython BLDSHARED="arm-none-linux-gnueabi-
gcc -static" CROSS_COMPILE=yes prefix=/home/marcelo/python


4) Android emulator install (trying to use the same path)


- Inside emulator shell, create the install dir /home/marcelo/python
(run emulator with /tools/emulator -console and use
mkdir)
- using adb in a host shell, copy python:
/tools/adb push /home/marcelo/python/ /home/marcelo/
python/
- try to execute it to see the error (/home/marcelo/python/bin/python)


5) references


5.1) http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python...
5.2) http://avr32linux.org/twiki/bin/view/Main/Python
5.3) http://www.cibomahto.com/?p=82

没有评论: