Sign in Join
Wiki copytemporary

Setup Cross Compile For ARM/es: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Setup Cross Compile For ARM/es

OldNewLine
1+## Como configurar Lazarus/FPC para compilación cruzada para arm-linux.
2+
3+Con este tutorial puedes generar un fichero binario que corre en dispositivos arm-linux. Se ha testeado con un Nokia N900 con "[Maemo 5 OS](http://maemo.org/)" (the gnu/linux Debian based OS, developed by [Nokia](http://maemo.nokia.com/videos/introducing-maemo-5/). Es un dispositivo arm-linux que funciona con GTK2 y QT4.6).
4+
5+Si lo que necesitas es un simple programa del tipo "command prompt"/"terminal", entonces de la sección #FPC for ARMve a Testeando programas de consola.
6+
7+**NOTA 1**: Todos los procedimientos se han testeado en una Máquina Virtual con [[http://www.ubuntu.com/ Ubuntu 9.10 - x86]] de sistema huesped, con Windows 7 como host (o máquina albergadora) y [[http://www.virtualbox.org/ VirtualBox 3.0.12]] como aplicación de virtualización (hypervisor). Es una instalación limpia, con todas las actualizaciones al día.
8+
9+**NOTA 2**: Reemplazar cada */home/user/* con tu trayectoria real de usuario. Todas las demás trayectorias se ponen simplemente como explicación. Si utilizas "[Maemo SDK Virtual Image](http://maemovmware.garage.maemo.org/2nd_edition/)", reemplaza cada */home/user/* con */home/maemo/*
10+
11+## Script automatizado
12+
13+Los scripts aportados anteriormente son obsoletos. Por favor mira [aquí](http://wiki.lazarus.freepascal.org/Lazarus_Manager) (ver en pagina de discusión para alternativas).
14+
15+## Cosas genéricas por hacer
16+
17+> **Warning:** Estas instrucciones son bastante antiguas - hacen referencia a la versión 2.2.4, a fecha de escribir este artículo es diciembre de 2013 con stable FPC is 2.6.2 y de esta traducción 2016 (ya con la 3.0.0) . Por favor ajustar para seguir esto y actualizar la página. Gracias.
18+
19+### Descargas
20+
21+- any starting compiler from the 2.2.4 branch (e.g. fpc-2.2.4-20091214.i386.rpm) from [HERE](http://www.hu.freepascal.org/lazarus) or [HERE](http://snapshots.lazarus.shikami.org/)). It is needed to compile \>= 2.2.4 fpc sources
22+- latest binutils.tar.gz (e.g. binutils-2.20.tar.gz) from [HERE](http://ftp.gnu.org/gnu/binutils/)
23+- latest [fpc.zip](http://ftp//ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip) from [HERE](http://www.freepascal.org/develop.var)
24+- latest Lazarus source zip (e.g. lazarus-0.9.29-23129-20091214-src.zip) from [HERE](http://www.hu.freepascal.org/lazarus) or [HERE](http://snapshots.lazarus.shikami.org/) (faster for me)
25+- target libs (You can grab from SDK or from arm-device. *See "#APPENDIX A: Testing console programs"*)
26+
27+### Unpack/copy all files in the respective directories
28+
29+FPC 2.2.4 installer:
30+
31+`~/fpc_tools/fpc_2.2.4/fpc-2.2.4-20091214.i386.rpm`
32+
33+Binutils sources:
34+
35+`~/fpc_tools/binutils-2.20/`
36+
37+Lazarus sources:
38+
39+`~/lazarus/`
40+
41+FPC 2.5.1 sources:
42+
43+`~/lazarus/fpc/2.5.1/`
44+
45+### Prepare Target Libs
46+
47+- See "#APPENDIX A: Testing console programs" to know how/where to find target libs
48+- Copy all target libs to ~/lazarus/fpc/libcross
49+
50+### Install dependencies
51+
52+``` bash
53+sudo apt-get install -y alien libncurses5-dev libXp-dev libgtk2.0-dev
54+```
55+
56+## Install & Configure Binutils
57+
58+### Compile binutils for arm-linux
59+
60+- If not already done, extract binutils-2.20.tar.gz in ~/fpc_tools/binutils-2.20
61+- Then type:
62+
63+``` bash
64+cd ~/fpc_tools/binutils-2.20
65+./configure --target=arm-linux --disable-werror
66+make
67+sudo make install
68+mkdir ~/lazarus/fpc/binutils
69+ln -s /usr/local/bin/arm-linux-ar ~/lazarus/fpc/binutils/ar
70+ln -s /usr/local/bin/arm-linux-ld ~/lazarus/fpc/binutils/ld
71+sudo mv /usr/local/bin/arm-linux-as /usr/local/bin/arm-linux-as_org
72+
73+sudo gedit /usr/local/bin/arm-linux-as
74+```
75+
76+- Paste:
77+
78+``` bash
79+#!/bin/sh
80+/usr/local/bin/arm-linux-as_org -meabi=5 $@
81+```
82+
83+**NOTE**: option *-meabi=5* force assembler to make binary *eabi v5* compatible. E.g. if you need eabi v4 you will change it in *-meabi=4*.
84+
85+- Save and close gedit
86+- Type:
87+
88+``` bash
89+sudo chmod +x /usr/local/bin/arm-linux-as
90+ln -s /usr/local/bin/arm-linux-as ~/lazarus/fpc/binutils/as
91+```
92+
93+## FPC
94+
95+### Install precompiled fpc 2.2.4 branch
96+
97+**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
98+
99+- Type:
100+
101+``` bash
102+sudo alien -i -c /home/user/fpc_tools/fpc_2.2.4/fpc-2.2.4-20091214.i386.rpm
103+```
104+
105+- Be sure that ppc386 is right installed, type:
106+
107+``` bash
108+which ppc386
109+```
110+
111+if ppc386 is in the path it returns the path (e.g. /usr/bin/ppc386)
112+
113+### Compile FPC from sources
114+
115+- Type:
116+
117+``` bash
118+cd ~/lazarus/fpc/2.5.1
119+make all OPT='-gl -O3p3' PP=/usr/bin/ppc386 (add NOGDB=1 at the end if asked)
120+sudo make install PP=/usr/bin/ppc386 PREFIX=/usr/ (add NOGDB=1 at the end if asked)
121+sudo rm /usr/bin/ppc386
122+sudo ln -s /usr/lib/fpc/2.5.1/ppc386 /usr/bin/ppc386
123+sudo mkdir /usr/share/fpcsrc/
124+sudo ln -sf ~/lazarus/fpc/2.5.1/ /usr/share/fpcsrc/
125+sudo /usr/lib/fpc/2.5.1/samplecfg /usr/lib/fpc/2.5.1/ /etc
126+```
127+
128+## FPC for ARM
129+
130+### Make FPC able to cross compile for arm-linux
131+
132+- Type:
133+
134+``` bash
135+cd ~/lazarus/fpc/2.5.1/
136+sudo make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/home/user/lazarus/fpc/binutils/ OPT=-dFPC_ARMEL INSTALL_PREFIX=/usr
137+```
138+
139+### Create custom fpc.cfg
140+
141+**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
142+
143+- Type:
144+
145+``` bash
146+gedit ~/.fpc.cfg
147+```
148+
149+- Paste in ~/.fpc.cfg:
150+
151+ #INCLUDE /etc/fpc.cfg
152+ #DEFINE DEMOTEST
153+ #DEFINE DEMOTEST1
154+ #DEFINE LAZARUS
155+
156+ -Fu/usr/lib/fpc/2.5.1/units/$fpctarget/*
157+ -Fl/usr/lib/fpc/2.5.1/units/$fpctarget/rtl/
158+
159+ -a
160+ -Sd
161+ -Xd
162+ -Xs
163+
164+ -O-
165+
166+ #IFDEF CPUARM
167+ -XP/home/user/lazarus/fpc/binutils/
168+ -Xr/usr/lib/fpc/2.5.1/units/arm-linux/rtl/
169+ -Xr/home/user/lazarus/fpc/libcross
170+ -XR/home/user/lazarus/fpc/
171+ -darm
172+ -Tlinux
173+ #ENDIF
174+
175+- save and close gedit
176+- Type:
177+
178+``` bash
179+sudo ln -sf /usr/lib/fpc/2.5.1/ppcrossarm /usr/local/bin/ppcarm
180+```
181+
182+## Lazarus
183+
184+If you don't need graphical programs, you can skip this section and go directly to #Appendix B: Target libs
185+
186+### Compile Lazarus
187+
188+- Type:
189+
190+``` bash
191+cd ~/lazarus
192+make clean all
193+```
194+
195+### Start Lazarus
196+
197+- Start Lazarus to see that everything is ok and then to compile LCL and Package Registration
198+- Type:
199+
200+``` bash
201+./lazarus
202+```
203+
204+### Configure Lazarus for cross Compile
205+
206+- Now you must cross compile the LCL and Package Registration, this part comes from [HERE](http://wiki.lazarus.freepascal.org/Cross_compiling#Cross_compiling_the_LCL).
207+- From the IDE:
208+ 1. In Tools -\> Options -\> Environment -\> Files, set the Compiler path to the path to fpc. Normally this is already done.
209+ 2. Then open Tools / Configure Build Lazarus / Advanced Build Options.
210+ 3. Set Target OS as *linux* and Target CPU as *arm*.
211+ 4. Set LCL and Package registration to Build (the middle radio button) and all other to None (left radio buttons).
212+ 5. Click the Build button.
213+
214+## Make your first arm-linux project in Lazarus
215+
216+### New Project
217+
218+- Start new project as application
219+- Put some component in main form to test (like button, memo and few other things)
220+
221+### Set Targets
222+
223+- From the IDE:
224+ 1. Set in Project / Compiler Options / Code generation / Target OS (-T): *Linux*
225+ 2. Set in Project / Compiler Options / Code generation / Target CPU family (-P): *arm*
226+ 3. Set in Project / Compiler Options / Other / Custom Option: enter -XParm-linux- into textbox
227+
228+### Add target libs to your project
229+
230+**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
231+
232+- From the IDE:
233+ 1. Set in Project / Compiler Options / Linking / Options (-k): *-L/home/user/lazarus/fpc/libcross*
234+ 2. Set in Project / Compiler Options / Compilation / Execute after / Command: *arm-linux-strip -s /path/to/your/project/binary* (where *"binary"* is the executable builded with Lazarus)
235+
236+### Build Project
237+
238+- Build Project as normal:
239+ 1. Hit keys Ctrl+F9
240+ 2. Run / Build
241+
242+### Time to run
243+
244+- Transfer the binary of your project on device
245+- Generally you must give executable permission to the binary directly on the device. If you work in terminal type:
246+
247+``` bash
248+chmod +x /path/where/is/YourProject
249+./path/where/is/YourProject
250+```
251+
252+<figure>
253+<img src="Kjow_hello-world.png" title="e.g. Maemo 5 running Lazarus graphical demo." width="300" />
254+<figcaption>e.g. Maemo 5 running Lazarus graphical demo.</figcaption>
255+</figure>
256+
257+## APPENDIX A: Testing console programs
258+
259+### Create a TestARM.pas
260+
261+- Type:
262+
263+``` bash
264+mkdir ~/dev/TestARM/
265+gedit ~/dev/TestARM/TestARM.pas
266+```
267+
268+- Paste this code:
269+
270+``` pascal
271+program test;
272+begin
273+ writeln('DATE ',{$i %DATE%});
274+ writeln('FPCTARGET ',{$i %FPCTARGET%});
275+ writeln('FPCTARGETCPU ',{$i %FPCTARGETCPU%});
276+ writeln('FPCTARGETOS ',{$i %FPCTARGETOS%});
277+ writeln('FPCVERSION ',{$i %FPCVERSION%});
278+end.
279+```
280+
281+- Type:
282+
283+``` bash
284+cd ~/dev/TestARM/
285+fpc -Tlinux -Parm -XParm-linux- TestARM.pas
286+```
287+
288+### Time to run
289+
290+- Transfer TestARM on device
291+- Generally you must give executable permission to *TestARM* directly on the device:
292+
293+``` bash
294+chmod +x /path/where/is/TestAMR
295+./path/where/is/TestAMR
296+```
297+
298+## Appendix B: Target libs
299+
300+You need target libs to assemble and link binary file. You can find them into the SDK of your device or into the device itself.
301+
302+E.g. for Nokia N900 you need to copy /lib/* and /usr/lib/* (no subdirs needed) that are present in the Nokia N900 root and you must merge all files to ~/lazarus/fpc/libcross/\
303+Finally, you need to rename each library *not found* by linker (ld) to the file name searched by linker itself.\
304+E.g. if you got this error
305+
306+`libX11.so not found (or incompatible)`
307+
308+and you have a file called *libX11.so.6.2.0*, then you need to rename it into *libX11.so*
309+
310+## See also
311+
312+- [[Android]] Article on setting up cross-compiling for Android on ARM
313+
314+---
315+*From the Free Pascal wiki, page "Setup Cross Compile For ARM/es", as it stood on 2020-02-26 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history