[Android] Building Free Pascal Compiler for Android

I think most of us heard about young mobile platform Android by Google.

Google recomend to use Java for developing applications for Android, but there nothing dificult to use gcc cross compiler to build applications on C or C++, in one of next post i will write how to build application/library on c/c++ using android toolchain.

So we can use Java or C/C++ but what should developers dothat prefer Pascal?

Today i will tell how to build Free Pascal Compiler that can build applications for android.

To build cross compiler we will need:

  1. Free Pascal Compiler (you can get it from http://freepascal.org/download.var)
  2. arm-eabi toolchain (android eabi will not work, we got error on linking) so we need download toolchain (you can get it from [there windows and linux versions] http://www.codesourcery.com/sgpp/lite/arm/portal/release644)
  3. Last Free Pascal Sources (get if ftom svn http://svn.freepascal.org/svn/fpc/trunk)

Thats all, install toolchain packages and we can build crosscompiler.

To build crosscompiler you need:

a) in terminal (cmd for Windows) go to root folder that contatin fpc sources from svn

b) and type:

make crossall CPU_TARGET=arm OS_TARGET=linux OPT=”-dFPC_ARMEL -O- -gl” CROSSPORT=”-O-” CROSSBINDIR=/home/dabeat/toolchain/arm-none-linux-gnueabi/arm-eabi/bin

Note: (CROSSBINDIR – this is full path to downloaded and installedtoolchain)

That should be enough, if everything ok in folder that contain fpc in folder compiler you will find ppcrossarm, this is our cross compiler.

Lets build simple application:

program Hello;
begin
WriteLn(‘Hello World’);
end.

to build in terminal (cmd for windows) go to folder that contain crosscompiler and type:

./ppcrossarm -Tlinux -O- -XP -Fu/home/dabeat/fpc/rtl/units/arm-linux/ -FD/home/dabeat/toolchain/arm-none-linux-gnueabi/arm-eabi/bin /home/dabeat/Hello.pp

Note: -FD key that say to crosscompiler path to toolchain

-Fu key that say to crosscompiler path to cross rlt

if there wasnt errors then lets test built application:

1) Run emulator (you can find it in sdk`s tools folder)

2) In tools folder you will also find tool adb use it too load application on emulator:

./adb push /home/dabeat/Hello data/Hello

3) Run loaded application:

./adb shell data/Hello

as result you will see:

Hello Word

Yep we got it :) There left one problem application aint exit (only Ctrl + C helps) :(

P.S. I built cross compiler on Linux Ubuntu but I`m sure that if you will do on Windows the same steps you will have the same result.

9 Responses to “[Android] Building Free Pascal Compiler for Android”

  1. 1
    Jorrit Says:

    Just noticed this post. I did the exact same thing about 9 months ago, had the same problem - app doesn’t exit.

    Tried talking with guys in #fpc but never figured it out…

    (btw reply through mail I just came here through Google)

  2. 2
    Marcelo-MasterManson Says:

    …. i search a app from android…. a compíler to dalvik or another VM …. do you know anyone?

  3. 3
    Gintas Says:

    Anyone tried to do this on Windows please paste the command you execute. I get error makefile:135: *** Compiler .exe not found. Stop.

  4. 4
    Pandora Says:

    Anyone have the compiled binaries? Please upload to http://www.box.net and drop a link here.

  5. 5
    Robert Says:

    Hi Alex. I am using the pascal compiler on my HTC Tattoo android mobile and it’s great but,
    I cant use the commands : Label, goto.string,char !!!
    Neither can I use uses!
    What am i missing here?
    What Pascal language do we talk about here?

    Best regards

  6. 6
    Twitter Trackbacks for Building Free Pascal Compiler for Android | Alex Mogurenko`s Blog [alexmogurenko.com] on Topsy.com Says:

    […] Building Free Pascal Compiler for Android | Alex Mogurenko`s Blog alexmogurenko.com/blog/programming/android-building-free-pascal-compiler-for-android – view page – cached This Article explain how to build fpc fro android Tweets about this link Topsy.Data.Twitter.User[’wizack’] = {”photo”:”http://s.twimg.com/a/1273620457/images/default_profile_0_normal.png”,”url”:”http://twitter.com/wizack”,”nick”:”wizack”}; wizack: “http://alexmogurenko.com/blog/programming/android-building-free-pascal-compiler-for-android/ http://fb.me/t8BQPTRn ” 16 minutes ago view tweet retweet Topsy.Data.Twitter.User[’wizack’] = {”photo”:”http://s.twimg.com/a/1273620457/images/default_profile_0_normal.png”,”url”:”http://twitter.com/wizack”,”nick”:”wizack”}; wizack: “http://alexmogurenko.com/blog/programming/android-building-free-pascal-compiler-for-android/ http://fb.me/w6kqcW3N ” 20 minutes ago view tweet retweet Filter tweets […]

  7. 7
    thierrybo Says:

    Hi,

    I have no Android mobile and neither tried cross compiling with freepascal before but today I had nothing to do so I tried to setup Android SDK ans fpc crosscompile setup and I finally suucceeded to run Hello World!

    Notice that I have not the CTRL-C issue. Perhaps due to newer FPC or Android SDK.

    A question. I naively believed that I could the Hello World on the ** emulator screen **, not on my computer. Perhaps to achieve this we must install “DEbian for Android” : http://www.androidfanatic.com/community-forums.html?func=view&id=2248&catid=9

  8. 8
    TheDude Says:

    thierrybo please tell us more about this :-) Do you mean to tell that FPC is ready for primetime action on Android?

  9. 9
    thierrybo Says:

    Uhm,

    I wonder if you said that because of the ‘CTRL-C issue’ or because of ‘“Debian for Android”?

    I just did the same thing shown on this blog post.

    Otherwise the “Debian for Android” is only for geeks and works only on some models.

    I did not experiment but you can only use freepascal to write native libraries that you use in regular java programs as embedded components. But as far as I searched, it seems impossible to write an entire application using only freepascal ( or C/C++).

Leave a Reply