0) Preface
0.1) The Operating System is Ubuntu 10.10
0.2) All the softwares are the latest stable version by April 12, 2011
1) Download the Source of Free Pascal Compiler
The ‘fpc-2.4.2.source.tar.gz’ on http://sourceforge.net/projects/freepascal/files/Source/2.4.2/
2) Install the fpc-source. Just extract it.
The root folder of fpc-source for me is ‘/home/victorhu/fpc-source’
3) Download the Arm-Eabi (Sourcery G++ Lite 2010.09-50 for ARM GNU/Linux)
The ‘IA32 GNU/Linux Installer’ on http://www.codesourcery.com/sgpp/lite/arm/portal/release1600
4) Install the Arm-Eabi (Sourcery G++ Lite 2010.09-50 for ARM GNU/Linux)
The installation need the system shell to be bash not dash which is default for Ubuntu. So
4.1) [shell]sudo dpkg-reconfigure -plow dash[/shell] Choose NO to make the bash as the system shell.
4.2) Goto the root folder of Arm-Eabi for me is ‘/home/victorhu/toolchain/’
4.3) [shell]chmod +x arm-2010.09-05-arm-none-linux-gnueabi.bin[/shell]
4.4) [shell]./arm-2010.09-05-arm-none-linux-gnueabi.bin[/shell]
5) Get the Cross Compiler
5.1) Goto the root folder of fpc-source
5.2) [shell]make crossall CPU_TARGET=arm OS_TARGET=linux OPT=”-dFPC_ARMEL -O- -gl” CROSSPORT=”-O-” CROSSBINDIR=/home/victorhu/toolchain/arm-none-linux-gnueabi/bin[/shell]
5.3) The ‘ppcrossarm’ under ‘/home/victorhu/fpc-source/compilers/’ is just what we want.
Note: CROSSBINDIR is depend on the folder of Arm-Eabi.
6) Write a Hello Word in Pascal
The path for me is /home/victorhu/hello.pas
[pascal]
Program hello;
begin
writeln(‘Hello World!’);
end.
[/pascal]
7) Compile the Hello World in Pascal via CrossCompile Environment.
7.1) Goto the folder contains ‘ppcrossarm’
7.2) [shell]./ppcrossarm -Tlinux -O- -XP -Fu/home/victorhu/fpc-source/rtl/units/arm-linux/ -FD/home/victorhu/toolchain/arm-none-linux-gnueabi/bin /home/victorhu/hello.pas[/shell]
Note: -Fu is the unit path, -FD is the compiler utilities path.
7.3) The ‘hello’ under ‘/home/victorhu/temp’ is just the what we want (not hello.pas).
8) Test the Crosscompiled Hello World in Android Emulator
8.1) the tools under Android SDK or the ADT of Eclipse is where we can find it.
8.2) Goto the adb root folder under Android SDK .
It’s ‘platform-tools’ under the main root folder of Android SDK now while it’s ‘tools’ before.
8.3) Test whether is device is connected.
[shell]./adb devices[/shell]
If it shows somthing like ‘Emulator-5544 device’ (for me), then it’s right.
8.4) Push the program into Android Emulator.
[shell]./adb push ~/hello /data/hello[/shell]
8.5) Run the program on the Android Emulator.
[shell]./adb shell data/hello[/shell]
If it shows ‘Hello World!’ (the result of the original program), then everything is done now!
9) Reference
9.1) http://alexmogurenko.com/blog/programming/android-building-free-pascal-compiler-for-android/
9.2) http://wiki.freepascal.org/Android_Interface
9.3) http://wiki.freepascal.org/Setup_Cross_Compile_For_ARM
P.S.本文参与“第二届 Google 暑期大学生博客分享大赛 – 2011 Android 成长篇”,感谢大家支持
2 responses to “Android平台下FreePascal的交叉编译器”
还是看8懂。。。。溜去看ubuntu10.04那里看看。。。。。。不要Spam我啊!!!
@艳文 这个我也才开始研究 也是半懂不懂的 呵呵