背景:1:我筆記本是XP(Intel處理器),虛擬機器中裝Ubuntu 10
2.fpc是2.4.2 lazarus版本是0.9.30 Sourcery G++ Lite 2010-09 java jdk 1.6 android 的模擬器 2.2
步驟:
1.安裝好fpc編譯器和lazarus 這一步略
2.下載fpc-source ,連結如下:The ‘fpc-2.4.2.source.tar.gz’ onhttp://sourceforge.net/projects/freepascal/files/Source/2.4.2/,
2.1 解壓縮即可,我放在home/hotcyy/ 下,即絕對路徑為home/hotcyy/fpc-source
3.下載Sourcery G++ Lite,連結:The ‘IA32 GNU/Linux Installer’ onhttp://www.codesourcery.com/sgpp/lite/arm/portal/release1600
3.1 在終端執行:sudo
dpkg-reconfigure
-plow dash,接著選擇No,繼續
3.2 到軟體包的檔案目錄 執行:chmod
+x
arm-2010.09-05-arm-none-linux-gnueabi.bin
3.3 安裝:./arm-2010.09-05-arm-none-linux-gnueabi.bin
我這邊的路徑為:/home/hotcyy/CodeSourcery/Sourcery_G++_Lite
3.4 安裝好之後一定要檢查環境變數,即驗證是否安裝成功。在終端運行arm-none-linux-gnueabi-gcc
-v 若顯示版本則證明安裝成功了,若不成功,這需要添加環境變數:export PATH=$HOME/hotcyy/CodeSourcery/Sourcery_G++_Lite/bin,或直接用vim編輯環境變數。
4
去fpc-source的目錄下,請先確認fpc-source/rtl/units/arm-linux檔案下存有*.ppu;*.o檔案等存在證明沒問題了 可進行下一步
執行:make
crossall CPU_TARGET=arm OS_TARGET=linux OPT="-dFPC_ARMEL -O- -gl" CROSSPORT="-O-" CROSSBINDIR=/home/hotcyy/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/bin
5.便在/home/hotcyy/fpc-source/compilers/目錄下產生了
ppcrossarm檔案
6.編寫一個簡單的Helloworld的pascal程式
略
7
到/home/hotcyy/fpc-source/compilers/此目錄下:執行 ./ppcrossarm
-Tlinux -O- -XP -Fu/home/hotcyy/fpc-source/rtl/units/arm-linux/ -FD/home/hotcyy/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/bin /home/hotcyy/dev/hello.pas
Note: -Fu is the unit path, -FD is
the compiler utilities path.
8.便在hello.pas目錄下頁產生hello和hello.o兩個檔案
9.裝好android的環境之後,啟動模擬器,執行:./adb push /home/hotcyy/dev/hello /data/hello (注意前面是源檔案路徑,後者路徑必須是data/*)
10. 繼而執行:./adb shell /data/hello 便在終端中看到了Hello World -----------------The END
Reference:
1) http://alexmogurenko.com/blog/programming/android-building-free-pascal-compiler-for-android/
2) http://wiki.freepascal.org/Android_Interface
3) http://wiki.freepascal.org/Setup_Cross_Compile_For_ARM
4)http://blog.huxuan.org/corsscompiler-to-run-free-pascal-on-android/