* * *

Author Topic: [Tutorial] Cross Compile for arm-linux (Finally it works!)  (Read 124400 times)

Kjooow

  • Jr. Member
  • **
  • Posts: 88
[Tutorial] Cross Compile for arm-linux (Finally it works!)
« on: December 03, 2009, 01:14:46 pm »
How To setup Lazarus/FPC for arm-linux cross compiling.

I decided to remove this post to link ONLY the authoritative/updated WiKi-tutorial.

Please follow these links:
« Last Edit: October 13, 2010, 03:04:47 pm by Kjooow »

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Cross Compile for arm-linux
« Reply #1 on: December 03, 2009, 05:06:18 pm »
It seems to me, ARM isn't the prefered target platform of most users. I didn't get any respond to my questions. Anyway, I would appreciate an updated tutorial. Maybe that helps growing the community.
Lazarus 1.7 (SVN) FPC 3.0.0

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: Cross Compile for arm-linux
« Reply #2 on: December 03, 2009, 06:17:41 pm »
It seems to me, ARM isn't the prefered target platform of most users. I didn't get any respond to my questions. Anyway, I would appreciate an updated tutorial. Maybe that helps growing the community.

For this reason I would the help to create a tutorial "step-by-step", so users could create itself all necessary for development. There is a lot of unknowledge about this and tutorials are often outdated or cryptic.

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: [Tutorial] Cross Compile for arm-linux
« Reply #3 on: December 10, 2009, 03:28:21 pm »
First post updated.

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: [Tutorial] Cross Compile for arm-linux
« Reply #4 on: December 11, 2009, 11:59:49 am »
Some notes from my experiences. First, I would suppose that fpc is installed, updated and used correctly. Omit the part until arm-linux from your tutorial. By the way, you say v2.2.4 and use 2.5.1. You just create Binutils and not Newlib. This have be done to have more function than "writeln" only. Actually, I appended some more options to configure binutils. Don't "cp" use "ln". I'm confused with your compiler name "ppcarm" instead of "ppcrossarm". I thought "cross" comes from the options crossinstall. You insert ARM options (i.e. -CfSOFT -CaEABI) into the fpc.cfg but add them to compilation too. Perhaps both are not needed since you created the compiler with them. AT least, a good tutorial should provide informations about the applied options. Why do you insert them, what happens, where are the files etc.

My procedure with binutils is as follows. I'm running Ubuntu where Synaptic or apt-get can be used to access repositories. How to create an ARM Toolchain is from the german wiki http://wiki.ubuntuusers.de/GNU_ARM-Toolchain

1. Synaptic -> binutils-source -> /usr/src/binutils -> binutils-2.19.1
download patch from http://sourceware.org/bugzilla/attachment.cgi?id=3058&action=view
  • patch -p0 -b -i binutils-2.19-arm.patch binutils-2.19/gas/config/tc-arm.c
  • ./configure --target=arm-elf --prefix=/opt/gnuarm --enable-interwork --enable-multilib --enable-target-optspace --with-float=soft
  • make all
  • sudo make install
  • sudo ln -s /opt/gnuarm/bin/* /usr/local/bin

2. Synaptic -> gcc-4.3-source -> /usr/src/gcc-4.3 -> gcc-4.3.3
  • replace ./gcc/config/arm/t-arm-elf by http://www.gnuarm.org/t-arm-elf
  • ./configure --target=arm-elf --prefix=/opt/gnuarm --enable-interwork --enable-multilib --enable-languages="c,c++" --enable-target-optspace --with-float=soft --with-newlib --with-headers=../../newlib/newlib-1.17.0/newlib/libc/include/ --disable-nls
  • sudo make all-gcc install-gcc
  • sudo ln -s /opt/gnuarm/bin/* /usr/local/bin

3. Synaptic -> newlib-source -> /usr/src/newlib -> newlib-1.17.0
  • ./configure --target=arm-elf --prefix=/opt/gnuarm --enable-interwork --enable-multilib --enable-target-optspace --with-float=soft
  • sudo make install

4. back to gcc (perhaps not necessary for freepascal)
  • sudo make all install (does not work for me)

After all it creates a structure in /opt/gnuarm which can be used to compile Hello-World. I was missing at least libgl and did not find a way to build it. So one can access different precompiled toolchains as well (http://www.gnuarm.com/, http://www.yagarto.de/, http://www.codesourcery.com/). I downloaded this file decompressed it to /opt (arm-2009q3) and applied that path to all further steps.

5. fpc
  • make distclean
  • make crosszipinstall CPU_TARGET=arm OS_TARGET=linux OPT="-dFPC_ARMEL" CROSSOPT="-XR/opt/arm-2009q3/arm-none-linux-gnueabi -dFPC_ARMEL -CfSOFT -Cparmv5" FPC=/usr/local/lib/fpc/2.5.1/ppcx64

- crosszipinstall to create but not install
- -XR<> root dir where as and ld can be found
- ppcx64 is the compiler on 64bit systems, for 32bit it is called ppc386

It results in a packed file like fpc-2.5.1.arm-linux.tar.gz just where the makefile resides. Unpack the content to /usr/local/lib/fpc... and create a link for ppcrossarm into /usr/local/bin. Now ppcrossarm can be used to compile sources

6. Compilation
  • ppcrossarm -Xd -Fl/opt/arm-2009q3/arm-none-linux-gnueabi/libc/usr/lib -CaEABI -Parm -CfSOFT -CpARMV5 Example.pas

-Xd don't use standard lib path
-Fl use directory to search for libs
I don't know if it works without -C options.
Lazarus 1.7 (SVN) FPC 3.0.0

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: [Tutorial] Cross Compile for arm-linux
« Reply #5 on: December 11, 2009, 02:03:41 pm »
Some notes from my experiences. First, I would suppose that fpc is installed, updated and used correctly. Omit the part until arm-linux from your tutorial. By the way, you say v2.2.4 and use 2.5.1. You just create Binutils and not Newlib. This have be done to have more function than "writeln" only. Actually, I appended some more options to configure binutils. Don't "cp" use "ln". I'm confused with your compiler name "ppcarm" instead of "ppcrossarm". I thought "cross" comes from the options crossinstall. You insert ARM options (i.e. -CfSOFT -CaEABI) into the fpc.cfg but add them to compilation too. Perhaps both are not needed since you created the compiler with them. AT least, a good tutorial should provide informations about the applied options. Why do you insert them, what happens, where are the files etc.

My procedure with binutils is as follows. I'm running Ubuntu where Synaptic or apt-get can be used to access repositories. How to create an ARM Toolchain is from the german wiki http://wiki.ubuntuusers.de/GNU_ARM-Toolchain

Hi, thanks for contribute.

My "tutorial" starts from a fresh linux (ubuntu 9.10 x86) installation, without any fpc/lazarus installed.

To compile daily snapshot of fpc (e.g. trunk revision 2.5.1) we need to install a precompiled version of fpc >= 2.2.4
For this reason first point of FPC section install it. On 2nd point of "Generic things" you can see that fpc source should be extracted on /home/user/lazarus/fpc/2.5.1/

So, now, you have an installed and working fpc_2.2.4 and sources of 2.5.1 version in a directory. In next steps we compile fpc_2.5.1 and we set it as default (replace 2.2.4). Now you have fpc_2.5.1 working on you machine.

After this, and Lazarus installation, I build latest binutils from their sources and I enable FPC to cross compile for arm.

What I miss now is Lazarus arm-linux compilation (such as arm-wince in lazarus)... I search for system units, but I don't understand where/how to give it to lazarus.

___

Why do you use "--target=arm-elf" instead of"--target=arm-linux"?

___

First post updated. Fixed some paths and some cp->ln
« Last Edit: December 11, 2009, 05:22:39 pm by Kjooow »

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: [Tutorial] Cross Compile for arm-linux
« Reply #6 on: December 11, 2009, 05:26:19 pm »
Quote
Why do you use "--target=arm-elf" instead of"--target=arm-linux"?
Binutils make procedure did give that names. I don't want to go more in detail but did you build newlib as well? And, if you read my post carefully you will see that I failed with creating binutils by myself.
Lazarus 1.7 (SVN) FPC 3.0.0

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: [Tutorial] Cross Compile for arm-linux
« Reply #7 on: December 11, 2009, 06:47:06 pm »
Quote
Why do you use "--target=arm-elf" instead of"--target=arm-linux"?
Binutils make procedure did give that names. I don't want to go more in detail but did you build newlib as well? And, if you read my post carefully you will see that I failed with creating binutils by myself.

But arm-elf is not arm-linux (e.g. http://sources.redhat.com/ml/crossgcc/2005-11/msg00028.html )... I don't know/understand...

If you try my steps:

Quote
Enable amr-linux cross compiling:

1) Compile binutils for arm-linux; if not already done, extract binutils-2.20.tar.gz in:
   ~/fpc_tools/binutils-2.20

2) cd ~/fpc_tools/binutils-2.20

3) ./configure --target=arm-linux --disable-werror

4) make

5) sudo make install

You will able to compile binutils "arm-linux-as, arm-linux-ar, arm-linux-ld, ..." yourself, so no other steps are necessarie to have binutils for arm-linux.

With this new "revision" (006) of first post, I can compile for arm-linux without errors and program runs on device. I can compile a "complex" example as "gp2x_tutorial", but I get linking error to -lSDL (i tried to add JediSDL to path, but maybe I'm mistaking something):

Code: [Select]
~/dev/gp2xdemo$ ppcarm gp2x_tutorial.dprFree Pascal Compiler version 2.5.1 [2009/12/11] for arm
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for ARM
Compiling gp2x_tutorial.dpr
Assembling gp2x_tutorial
Linking gp2x_tutorial
/home/kjow/lazarus/fpc/binutils/ld: cannot find -lSDL
gp2x_tutorial.dpr(137,45) Error: Error while linking
gp2x_tutorial.dpr(137,45) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

or with parameters:   -Xd -CaEABI -CfSOFT -CpARMV5

Code: [Select]
ppcarm  -Xd -CaEABI -CfSOFT -CpARMV5 gp2x_tutorial.dpr
Free Pascal Compiler version 2.5.1 [2009/12/11] for arm
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for ARM
Compiling gp2x_tutorial.dpr
Assembling gp2x_tutorial
Linking gp2x_tutorial
/home/kjow/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libSDL.so when searching for -lSDL
/home/kjow/lazarus/fpc/binutils/ld: skipping incompatible /usr/lib/libSDL.a when searching for -lSDL
/home/kjow/lazarus/fpc/binutils/ld: cannot find -lSDL
gp2x_tutorial.dpr(137,45) Error: Error while linking
gp2x_tutorial.dpr(137,45) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

In Lazarus I get:

Code: [Select]
Recompiling WSLCLClasses, checksum changed for LCLProc
wslclclasses.pp(32,56) Fatal: Can't find unit WSLCLClasses used by LCLClasses
« Last Edit: December 11, 2009, 06:51:21 pm by Kjooow »

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: [Tutorial] Cross Compile for arm-linux
« Reply #8 on: December 15, 2009, 12:16:21 pm »
Big update at first post!

With these steps I can compile, assemble and almost link. Yes, I have a problem with two libraries:

All messages returned by Lazarus IDE:

/home/kjow/lazarus/fpc/libcross/libexpat.so.1: undefined reference to `__aeabi_unwind_cpp_pr1@GCC_3.5'
/home/kjow/lazarus/fpc/libcross/libglib-2.0.so: undefined reference to `__aeabi_unwind_cpp_pr0@GCC_3.5'
LAzARM.lpr(22) Error: Error while linking
LAzARM.lpr(22) Fatal: There were 1 errors compiling module, stopping


Do you know how to solve this undefined reference to `__aeabi_unwind_cpp_pr0@GCC_3.5'?

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: [Tutorial] Cross Compile for arm-linux
« Reply #9 on: December 15, 2009, 04:07:00 pm »
IT WORKS!!!  :o :D

I was in wrong simply with bad target libs :)
I made a copy of /lib and /usr/lib of Nokia N900 and renamed the libs "not found" (generally from libXXX.so.0.1234.1 to libXXX.so however Messages of IDE tells me everything)

Here the screenshot!

Tutorial above is working at 100% on a new/fresh installation of Ubuntu 9.10 x86.

alter

  • Full Member
  • ***
  • Posts: 151
    • KSP website
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #10 on: December 15, 2009, 04:23:13 pm »
I never used Maemo but can't you simply use ldconfig to generate missing symlinks?

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #11 on: December 15, 2009, 04:34:44 pm »
I never used Maemo but can't you simply use ldconfig to generate missing symlinks?

I don't know ldconfig, I'm not expert of linux develop and more less of cross compiling.
I grabbed libs needed from the device and now it build projects well :)

danzman

  • New member
  • *
  • Posts: 6
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #12 on: December 21, 2009, 10:34:23 pm »
Sorry for butting in. Have you guys done anything more than the "hello world"? I would love to make FPC/Lazarus work as I am more at home with Pascal. If we can do serious programming with FPC then we're in business 8)

Kjooow

  • Jr. Member
  • **
  • Posts: 88
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #13 on: December 21, 2009, 10:41:05 pm »
NOTE 1, on First post updated ;)

danzman

  • New member
  • *
  • Posts: 6
Re: [Tutorial] Cross Compile for arm-linux (Finally it works!)
« Reply #14 on: December 22, 2009, 02:30:50 pm »
I got my Ubuntu 9.10 box running with Lazarus already installed. I also have Maemo5 SDK installed with GTK and scratchbox. Everything I have on the box is my attempt to develop an app for Nokia N900. Would I have any problem adding FPC capability to develop app for N900?

Also, reading through the thread left me in a confused state. It could be my problem but can I impose on you gurus to rewrite your tutorial? Thanks. :-[

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus