Cross-compile Python to Embedded arm (support for import sqlite3, datetime, etc.) ----- Cross Compiling Python for Embedded Linux, Cross-compile
This is the Virgo blog of my graduation brother. I hope you will not try it !!!
Welcome to follow the graduation blog Garden Original http://www.cnblogs.com/hit-python/
Due to the needs of the lab project, I 'd like to ask my graduation brother to start learning Python at last night. I am a little obsessive. I have to install new software, so I installed python on Windows (and I also buried a ray for myself ). I installed Python-2.7.3 on a Linux machine before. I thought the Python advanced version was backward compatible. So I started to find my graduation brother's path to stepping on thunder... raw_input (), '', socket communication... in short, various versions are incompatible !!!
To get down to the truth, the lab for graduation (hereinafter referred to as graduation) is a XXXXXX (1MBytes is omitted here ). In short, it is a "awesome" lab under a university with Chinese characteristics.
Previous senior brothers and sisters used Linux C as the development language of the ARM-Linux Embedded System (mainly for network communication ). However, after I came to the lab, I found that many people were exploring the fish. The level of C language was almost ...........
In order not to go from generation to generation, I want to convert the development language into Python, which makes it possible for later students to quickly master a technology. (Don't be as confused as learning C !!!)
So... the problem is coming!
I have heard of Python running in Linux (no one has heard of it). How can I port Python to ARM?
Fortunately, the hard work of ARM after graduation is still acceptable. I spent two seconds thinking:
1: definitely go to the official source code (amount, I should not be able to write it out anyway)
2: You must use a cross compiler. (well, anyone who is willing to read this blog should know what a cross compiler is)
3: You need to compile it yourself (Nima. Can you leave me alone after graduation)
What's wrong !!!
Now, I want to know how to edit the blog garden after graduation!
Preparations before transplantation:
1. Linux operating system (ubuntu 12.04)
2. in Linux, There is a cross compiler (this compiler must be compatible with your embedded device). The cross compiler for graduation is: arm-xilinx-linux-gnueabi-gcc.
3. For the python source code package, go to ftp on the official website.
Attachment: documents contributed by graduation
OK, start! Take Python-2.7.3 as an example.
1/home/liu # tar jxvf Python-2.7.3.tar.bz2
2/home/liu # cd Python-2.7.3/
Run the configuration file to generate necessary Makefile and other files.
3/home/liu/Python-2.7.3 #./configure
Compile python Parser/pgen for PC
4/home/liu/Python-2.7.3 # make python Parser/pgen
Move the generated PC version to hostpython
5/home/liu/Python-2.7.3 # mv python hostpython
Move the generated PC interpreter to Parser/hostpgen
6/home/liu/Python-2.7.3 # mv Parser/pgen Parser/hostpgen
Clear unnecessary files
7 make distclean
The following sections involve cross-compiling Python
Install the patch first:
8/home/liu/Python-2.7.3 # patch-p1 <<Your patch path>Python-2.7.3-xcompile.patch
Set necessary environment variables
Set Cross Compiler
9/home/liu/Python-2.7.3 # CC = arm-xilinx-linux-gnueabi-gcc
Set the C ++ Cross Compiler
10/home/liu/Python-2.7.3 # CXX = arm-xilinx-linux-gnueabi-g ++
Set AR
11/home/liu/Python-2.7.3 # AR = arm-xilinx-linux-gnueabi-ar
Set RANLIB
12/home/liu/Python-2.7.3 # RANLIB = arm-xilinx-linux-gnueabi-ranlib
Generate Makefile conforming to the Cross-Compiler
13/home/liu/Python-2.7.3 #./configure -- host = arm-xilinx-linux-gnueabi -- prefix =/python
Make
14/home/liu/Python-2.7.3 # make HOSTPYTHON =. /hostpython HOSTPGEN =. /Parser/hostpgen BLDSHARED = "arm-xilinx-linux-gnueabi-gcc-shared" CROSS_COMPILE = arm-xilinx-linux-gnueabi-CROSS_COMPILE_TARGET = yes
This step will find that many modules are missing. These missing modules will cause import sqlite3, ssl, and other failures after running python. (No matter how you add this module later)
Install make install to a specified file
15/home/liu/Python-2.7.3 # make install HOSTPYTHON =. /hostpython BLDSHARED = "arm-xilinx-linux-gnueabi-gcc-shared" CROSS_COMPILE = arm-xilinx-linux-gnueabi-CROSS_COMPILE_TARGET = yes prefix =/home/liu/Python-2.7.3 /_ install
In this case, files that can be executed on ARM are generated in/home/liu/Python-2.7.3/_ install.
Check the ls _ install
16 ls _ install. in the bin directory, there is an arm executable Python binary file.
Test:
Copy the _ install Folder to the ARM file system.
17 cd<Your path>/_ Install/bin (note: this operation is performed on ARM)
./Python
OK. The migration is successful!
Write a few small codes and test it!
Unlike many versions on the Internet, you cannot import datatime, time, socket or something.
In addition, the above part is made by two foreign friends.
1: http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
2: http://www.cnx-software.com/2011/02/04/cross-compiling-python-for-mips-and-arm-platforms/
But sqlite is not supported yet. Why? Let's guess, I went to dinner first. Continue writing tomorrow. sqlite3 has been successfully supported, and it is absolutely original for graduation !!!
Cross-2953 in Embedded cross-compilation is different from cross-341.
Which platform do you mean? Only a version number is provided, and the compiling environment is not even mentioned. How can this problem be answered?
How to cross-compile libxml2 and port sqlite3 to arm Development Board
Configure the file first, then use the cross compiler to compile the file, and then install it to a folder. Copy the content of install to the/usr or/usr/local directory of the Development Board file system!