Sign in Join
Wiki copytemporary

Setup Cross Compile For ARM/es: what changed

Revision 3 to 4. 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
31-`~/fpc_tools/fpc_2.2.4/fpc-2.2.4-20091214.i386.rpm`
31+```text
32+~/fpc_tools/fpc_2.2.4/fpc-2.2.4-20091214.i386.rpm
33+```
3234
3335Binutils sources:
3436
35-`~/fpc_tools/binutils-2.20/`
37+```text
38+~/fpc_tools/binutils-2.20/
39+```
3640
3741Lazarus sources:
3842
39-`~/lazarus/`
43+```text
44+~/lazarus/
45+```
4046
4147FPC 2.5.1 sources:
4248
43-`~/lazarus/fpc/2.5.1/`
49+```text
50+~/lazarus/fpc/2.5.1/
51+```
4452
4553### Prepare Target Libs
4654
4755- See "#APPENDIX A: Testing console programs" to know how/where to find target libs
4856- Copy all target libs to ~/lazarus/fpc/libcross
4957
5058### Install dependencies
5159
5260``` bash
5361sudo apt-get install -y alien libncurses5-dev libXp-dev libgtk2.0-dev
5462```
5563
5664## Install & Configure Binutils
5765
5866### Compile binutils for arm-linux
5967
6068- If not already done, extract binutils-2.20.tar.gz in ~/fpc_tools/binutils-2.20
6169- Then type:
6270
6371``` bash
6472cd ~/fpc_tools/binutils-2.20
6573./configure --target=arm-linux --disable-werror
6674make
6775sudo make install
6876mkdir ~/lazarus/fpc/binutils
6977ln -s /usr/local/bin/arm-linux-ar ~/lazarus/fpc/binutils/ar
7078ln -s /usr/local/bin/arm-linux-ld ~/lazarus/fpc/binutils/ld
7179sudo mv /usr/local/bin/arm-linux-as /usr/local/bin/arm-linux-as_org
7280
7381sudo gedit /usr/local/bin/arm-linux-as
7482```
7583
7684- Paste:
7785
7886``` bash
7987#!/bin/sh
8088/usr/local/bin/arm-linux-as_org -meabi=5 $@
8189```
8290
8391**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*.
8492
8593- Save and close gedit
8694- Type:
8795
8896``` bash
8997sudo chmod +x /usr/local/bin/arm-linux-as
9098ln -s /usr/local/bin/arm-linux-as ~/lazarus/fpc/binutils/as
9199```
92100
93101## FPC
94102
95103### Install precompiled fpc 2.2.4 branch
96104
97105**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
98106
99107- Type:
100108
101109``` bash
102110sudo alien -i -c /home/user/fpc_tools/fpc_2.2.4/fpc-2.2.4-20091214.i386.rpm
103111```
104112
105113- Be sure that ppc386 is right installed, type:
106114
107115``` bash
108116which ppc386
109117```
110118
111119if ppc386 is in the path it returns the path (e.g. /usr/bin/ppc386)
112120
113121### Compile FPC from sources
114122
115123- Type:
116124
117125``` bash
118126cd ~/lazarus/fpc/2.5.1
119127make all OPT='-gl -O3p3' PP=/usr/bin/ppc386 (add NOGDB=1 at the end if asked)
120128sudo make install PP=/usr/bin/ppc386 PREFIX=/usr/ (add NOGDB=1 at the end if asked)
121129sudo rm /usr/bin/ppc386
122130sudo ln -s /usr/lib/fpc/2.5.1/ppc386 /usr/bin/ppc386
123131sudo mkdir /usr/share/fpcsrc/
124132sudo ln -sf ~/lazarus/fpc/2.5.1/ /usr/share/fpcsrc/
125133sudo /usr/lib/fpc/2.5.1/samplecfg /usr/lib/fpc/2.5.1/ /etc
126134```
127135
128136## FPC for ARM
129137
130138### Make FPC able to cross compile for arm-linux
131139
132140- Type:
133141
134142``` bash
135143cd ~/lazarus/fpc/2.5.1/
136144sudo make crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/home/user/lazarus/fpc/binutils/ OPT=-dFPC_ARMEL INSTALL_PREFIX=/usr
137145```
138146
139147### Create custom fpc.cfg
140148
141149**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
142150
143151- Type:
144152
145153``` bash
146154gedit ~/.fpc.cfg
147155```
148156
149157- Paste in ~/.fpc.cfg:
150158
151159 #INCLUDE /etc/fpc.cfg
152160 #DEFINE DEMOTEST
153161 #DEFINE DEMOTEST1
154162 #DEFINE LAZARUS
155163
156164 -Fu/usr/lib/fpc/2.5.1/units/$fpctarget/*
157165 -Fl/usr/lib/fpc/2.5.1/units/$fpctarget/rtl/
158166
159167 -a
160168 -Sd
161169 -Xd
162170 -Xs
163171
164172 -O-
165173
166174 #IFDEF CPUARM
167175 -XP/home/user/lazarus/fpc/binutils/
168176 -Xr/usr/lib/fpc/2.5.1/units/arm-linux/rtl/
169177 -Xr/home/user/lazarus/fpc/libcross
170178 -XR/home/user/lazarus/fpc/
171179 -darm
172180 -Tlinux
173181 #ENDIF
174182
175183- save and close gedit
176184- Type:
177185
178186``` bash
179187sudo ln -sf /usr/lib/fpc/2.5.1/ppcrossarm /usr/local/bin/ppcarm
180188```
181189
182190## Lazarus
183191
184192If you don't need graphical programs, you can skip this section and go directly to #Appendix B: Target libs
185193
186194### Compile Lazarus
187195
188196- Type:
189197
190198``` bash
191199cd ~/lazarus
192200make clean all
193201```
194202
195203### Start Lazarus
196204
197205- Start Lazarus to see that everything is ok and then to compile LCL and Package Registration
198206- Type:
199207
200208``` bash
201209./lazarus
202210```
203211
204212### Configure Lazarus for cross Compile
205213
206214- 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).
207215- From the IDE:
208216 1. In Tools -\> Options -\> Environment -\> Files, set the Compiler path to the path to fpc. Normally this is already done.
209217 2. Then open Tools / Configure Build Lazarus / Advanced Build Options.
210218 3. Set Target OS as *linux* and Target CPU as *arm*.
211219 4. Set LCL and Package registration to Build (the middle radio button) and all other to None (left radio buttons).
212220 5. Click the Build button.
213221
214222## Make your first arm-linux project in Lazarus
215223
216224### New Project
217225
218226- Start new project as application
219227- Put some component in main form to test (like button, memo and few other things)
220228
221229### Set Targets
222230
223231- From the IDE:
224232 1. Set in Project / Compiler Options / Code generation / Target OS (-T): *Linux*
225233 2. Set in Project / Compiler Options / Code generation / Target CPU family (-P): *arm*
226234 3. Set in Project / Compiler Options / Other / Custom Option: enter -XParm-linux- into textbox
227235
228236### Add target libs to your project
229237
230238**REMEMBER TO CHANGE EVERY**/home/user/**WITH YOUR OWN USER PATH!**
231239
232240- From the IDE:
233241 1. Set in Project / Compiler Options / Linking / Options (-k): *-L/home/user/lazarus/fpc/libcross*
234242 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)
235243
236244### Build Project
237245
238246- Build Project as normal:
239247 1. Hit keys Ctrl+F9
240248 2. Run / Build
241249
242250### Time to run
243251
244252- Transfer the binary of your project on device
245253- Generally you must give executable permission to the binary directly on the device. If you work in terminal type:
246254
247255``` bash
248256chmod +x /path/where/is/YourProject
249257./path/where/is/YourProject
250258```
251259
252260![](/wiki-images/0/08/Kjow_hello-world.png)
253261
254262## APPENDIX A: Testing console programs
255263
256264### Create a TestARM.pas
257265
258266- Type:
259267
260268``` bash
261269mkdir ~/dev/TestARM/
262270gedit ~/dev/TestARM/TestARM.pas
263271```
264272
265273- Paste this code:
266274
267275``` pascal
268276program test;
269277begin
270278 writeln('DATE ',{$i %DATE%});
271279 writeln('FPCTARGET ',{$i %FPCTARGET%});
272280 writeln('FPCTARGETCPU ',{$i %FPCTARGETCPU%});
273281 writeln('FPCTARGETOS ',{$i %FPCTARGETOS%});
274282 writeln('FPCVERSION ',{$i %FPCVERSION%});
275283end.
276284```
277285
278286- Type:
279287
280288``` bash
281289cd ~/dev/TestARM/
282290fpc -Tlinux -Parm -XParm-linux- TestARM.pas
283291```
284292
285293### Time to run
286294
287295- Transfer TestARM on device
288296- Generally you must give executable permission to *TestARM* directly on the device:
289297
290298``` bash
291299chmod +x /path/where/is/TestAMR
292300./path/where/is/TestAMR
293301```
294302
295303## Appendix B: Target libs
296304
297305You need target libs to assemble and link binary file. You can find them into the SDK of your device or into the device itself.
298306
299307E.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/\
300308Finally, you need to rename each library *not found* by linker (ld) to the file name searched by linker itself.\
301309E.g. if you got this error
302310
303-`libX11.so not found (or incompatible)`
311+```text
312+libX11.so not found (or incompatible)
313+```
304314
305315and you have a file called *libX11.so.6.2.0*, then you need to rename it into *libX11.so*
306316
307317## See also
308318
309319- [[Android]] Article on setting up cross-compiling for Android on ARM
310320
311321---
312322*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