Sign in Join
Wiki copytemporary

Setup Cross Compile For ARM/es: what changed

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

OldNewLine
11## Como configurar Lazarus/FPC para compilación cruzada para arm-linux.
22
33Con 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).
44
55Si 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.
66
77**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.
88
99**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/*
1010
1111## Script automatizado
1212
1313Los scripts aportados anteriormente son obsoletos. Por favor mira [aquí](http://wiki.lazarus.freepascal.org/Lazarus_Manager) (ver en pagina de discusión para alternativas).
1414
1515## Cosas genéricas por hacer
1616
1717> **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.
1818
1919### Descargas
2020
2121- 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
2222- latest binutils.tar.gz (e.g. binutils-2.20.tar.gz) from [HERE](http://ftp.gnu.org/gnu/binutils/)
2323- latest [fpc.zip](http://ftp//ftp.freepascal.org/pub/fpc/snapshot/trunk/source/fpc.zip) from [HERE](http://www.freepascal.org/develop.var)
2424- 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)
2525- target libs (You can grab from SDK or from arm-device. *See "#APPENDIX A: Testing console programs"*)
2626
2727### Unpack/copy all files in the respective directories
2828
2929FPC 2.2.4 installer:
3030
3131`~/fpc_tools/fpc_2.2.4/fpc-2.2.4-20091214.i386.rpm`
3232
3333Binutils sources:
3434
3535`~/fpc_tools/binutils-2.20/`
3636
3737Lazarus sources:
3838
3939`~/lazarus/`
4040
4141FPC 2.5.1 sources:
4242
4343`~/lazarus/fpc/2.5.1/`
4444
4545### Prepare Target Libs
4646
4747- See "#APPENDIX A: Testing console programs" to know how/where to find target libs
4848- Copy all target libs to ~/lazarus/fpc/libcross
4949
5050### Install dependencies
5151
5252``` bash
5353sudo apt-get install -y alien libncurses5-dev libXp-dev libgtk2.0-dev
5454```
5555
5656## Install & Configure Binutils
5757
5858### Compile binutils for arm-linux
5959
6060- If not already done, extract binutils-2.20.tar.gz in ~/fpc_tools/binutils-2.20
6161- Then type:
6262
6363``` bash
6464cd ~/fpc_tools/binutils-2.20
6565./configure --target=arm-linux --disable-werror
6666make
6767sudo make install
6868mkdir ~/lazarus/fpc/binutils
6969ln -s /usr/local/bin/arm-linux-ar ~/lazarus/fpc/binutils/ar
7070ln -s /usr/local/bin/arm-linux-ld ~/lazarus/fpc/binutils/ld
7171sudo mv /usr/local/bin/arm-linux-as /usr/local/bin/arm-linux-as_org
7272
7373sudo gedit /usr/local/bin/arm-linux-as
7474```
7575
7676- Paste:
7777
7878``` bash
7979#!/bin/sh
8080/usr/local/bin/arm-linux-as_org -meabi=5 $@
8181```
8282
8383**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*.
8484
8585- Save and close gedit
8686- Type:
8787
8888``` bash
8989sudo chmod +x /usr/local/bin/arm-linux-as
9090ln -s /usr/local/bin/arm-linux-as ~/lazarus/fpc/binutils/as
9191```
9292
9393## FPC
9494
9595### Install precompiled fpc 2.2.4 branch
9696
9797**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
9898
9999- Type:
100100
101101``` bash
102102sudo alien -i -c /home/user/fpc_tools/fpc_2.2.4/fpc-2.2.4-20091214.i386.rpm
103103```
104104
105105- Be sure that ppc386 is right installed, type:
106106
107107``` bash
108108which ppc386
109109```
110110
111111if ppc386 is in the path it returns the path (e.g. /usr/bin/ppc386)
112112
113113### Compile FPC from sources
114114
115115- Type:
116116
117117``` bash
118118cd ~/lazarus/fpc/2.5.1
119119make all OPT='-gl -O3p3' PP=/usr/bin/ppc386 (add NOGDB=1 at the end if asked)
120120sudo make install PP=/usr/bin/ppc386 PREFIX=/usr/ (add NOGDB=1 at the end if asked)
121121sudo rm /usr/bin/ppc386
122122sudo ln -s /usr/lib/fpc/2.5.1/ppc386 /usr/bin/ppc386
123123sudo mkdir /usr/share/fpcsrc/
124124sudo ln -sf ~/lazarus/fpc/2.5.1/ /usr/share/fpcsrc/
125125sudo /usr/lib/fpc/2.5.1/samplecfg /usr/lib/fpc/2.5.1/ /etc
126126```
127127
128128## FPC for ARM
129129
130130### Make FPC able to cross compile for arm-linux
131131
132132- Type:
133133
134134``` bash
135135cd ~/lazarus/fpc/2.5.1/
136136sudo make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/home/user/lazarus/fpc/binutils/ OPT=-dFPC_ARMEL INSTALL_PREFIX=/usr
137137```
138138
139139### Create custom fpc.cfg
140140
141141**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
142142
143143- Type:
144144
145145``` bash
146146gedit ~/.fpc.cfg
147147```
148148
149149- Paste in ~/.fpc.cfg:
150150
151151 #INCLUDE /etc/fpc.cfg
152152 #DEFINE DEMOTEST
153153 #DEFINE DEMOTEST1
154154 #DEFINE LAZARUS
155155
156156 -Fu/usr/lib/fpc/2.5.1/units/$fpctarget/*
157157 -Fl/usr/lib/fpc/2.5.1/units/$fpctarget/rtl/
158158
159159 -a
160160 -Sd
161161 -Xd
162162 -Xs
163163
164164 -O-
165165
166166 #IFDEF CPUARM
167167 -XP/home/user/lazarus/fpc/binutils/
168168 -Xr/usr/lib/fpc/2.5.1/units/arm-linux/rtl/
169169 -Xr/home/user/lazarus/fpc/libcross
170170 -XR/home/user/lazarus/fpc/
171171 -darm
172172 -Tlinux
173173 #ENDIF
174174
175175- save and close gedit
176176- Type:
177177
178178``` bash
179179sudo ln -sf /usr/lib/fpc/2.5.1/ppcrossarm /usr/local/bin/ppcarm
180180```
181181
182182## Lazarus
183183
184184If you don't need graphical programs, you can skip this section and go directly to #Appendix B: Target libs
185185
186186### Compile Lazarus
187187
188188- Type:
189189
190190``` bash
191191cd ~/lazarus
192192make clean all
193193```
194194
195195### Start Lazarus
196196
197197- Start Lazarus to see that everything is ok and then to compile LCL and Package Registration
198198- Type:
199199
200200``` bash
201201./lazarus
202202```
203203
204204### Configure Lazarus for cross Compile
205205
206206- 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).
207207- From the IDE:
208208 1. In Tools -\> Options -\> Environment -\> Files, set the Compiler path to the path to fpc. Normally this is already done.
209209 2. Then open Tools / Configure Build Lazarus / Advanced Build Options.
210210 3. Set Target OS as *linux* and Target CPU as *arm*.
211211 4. Set LCL and Package registration to Build (the middle radio button) and all other to None (left radio buttons).
212212 5. Click the Build button.
213213
214214## Make your first arm-linux project in Lazarus
215215
216216### New Project
217217
218218- Start new project as application
219219- Put some component in main form to test (like button, memo and few other things)
220220
221221### Set Targets
222222
223223- From the IDE:
224224 1. Set in Project / Compiler Options / Code generation / Target OS (-T): *Linux*
225225 2. Set in Project / Compiler Options / Code generation / Target CPU family (-P): *arm*
226226 3. Set in Project / Compiler Options / Other / Custom Option: enter -XParm-linux- into textbox
227227
228228### Add target libs to your project
229229
230230**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
231231
232232- From the IDE:
233233 1. Set in Project / Compiler Options / Linking / Options (-k): *-L/home/user/lazarus/fpc/libcross*
234234 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)
235235
236236### Build Project
237237
238238- Build Project as normal:
239239 1. Hit keys Ctrl+F9
240240 2. Run / Build
241241
242242### Time to run
243243
244244- Transfer the binary of your project on device
245245- Generally you must give executable permission to the binary directly on the device. If you work in terminal type:
246246
247247``` bash
248248chmod +x /path/where/is/YourProject
249249./path/where/is/YourProject
250250```
251251
252-<figure>
253252<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>
256253
257254## APPENDIX A: Testing console programs
258255
259256### Create a TestARM.pas
260257
261258- Type:
262259
263260``` bash
264261mkdir ~/dev/TestARM/
265262gedit ~/dev/TestARM/TestARM.pas
266263```
267264
268265- Paste this code:
269266
270267``` pascal
271268program test;
272269begin
273270 writeln('DATE ',{$i %DATE%});
274271 writeln('FPCTARGET ',{$i %FPCTARGET%});
275272 writeln('FPCTARGETCPU ',{$i %FPCTARGETCPU%});
276273 writeln('FPCTARGETOS ',{$i %FPCTARGETOS%});
277274 writeln('FPCVERSION ',{$i %FPCVERSION%});
278275end.
279276```
280277
281278- Type:
282279
283280``` bash
284281cd ~/dev/TestARM/
285282fpc -Tlinux -Parm -XParm-linux- TestARM.pas
286283```
287284
288285### Time to run
289286
290287- Transfer TestARM on device
291288- Generally you must give executable permission to *TestARM* directly on the device:
292289
293290``` bash
294291chmod +x /path/where/is/TestAMR
295292./path/where/is/TestAMR
296293```
297294
298295## Appendix B: Target libs
299296
300297You need target libs to assemble and link binary file. You can find them into the SDK of your device or into the device itself.
301298
302299E.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/\
303300Finally, you need to rename each library *not found* by linker (ld) to the file name searched by linker itself.\
304301E.g. if you got this error
305302
306303`libX11.so not found (or incompatible)`
307304
308305and you have a file called *libX11.so.6.2.0*, then you need to rename it into *libX11.so*
309306
310307## See also
311308
312309- [[Android]] Article on setting up cross-compiling for Android on ARM
313310
314311---
315312*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