Sign in Join
Wiki copytemporary

Cross compiling/fr: what changed

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

OldNewLine
11# avant-propos
22
33Ceci est une brève introduction pour les débutants. Les sections suivantes décrivent comment configurer un système pour une compilation croisée, ce qui signifie travailler sous linux et créer des exécutables win32 (ou freebsd ou dawin, ou ...). FreePascal est un compilateur et convertit fondamentalement des sources en fichiers binaire (langage machine). Ces fichiers binaires contiennent également des informations sur la manière dont le système d'exploitation démarre le fichier exécutable. Par conséquent, ces fichiers binaires sont spécifiques à la plate-forme. FreePascal lui-même n'a pas besoin de beaucoup de configuration. Il peut créer des fichiers binaires pour de nombreuses plate-formes. Il suffit de lui dire de le faire. Mais le compilateur est seulement une partie. Il y a aussi l'assembleur et l'éditeur de liens. Et ces outils ne sont pas en mesure de créer du code croisé. C'est pourquoi nous avons à créer un éditeur de lien spécial 'ld' et un assembleur 'as' pour chaque plate-forme cible. Ce sont les binutils. Après la création des outils croisés, toutes les unités pascal seront cross compilées. Par exemple, à ce moment-là il y a un fichier system.ppu pour chaque plate-forme cible. Alors votre fichier de configuration fpc sera configuré, de sorte que la compilation croisée devient si facile, que vous pouvez oublier tous les détails ennuyeux. La même chose sera faite pour la LCL - la bibliothèque de composants de lazarus. Et après cela, vous pouvez faire la compilation croisée des programmes en pascal pour win32. Soit lancer les avec wine soit copiez les vers une machine Windows et testez-les là.
44
55## Étapes de base
66
77Il y a plusieurs étapes qui sont obligatoires pour faire de la cross-compilation :
88
991. Vous devez avoir le compilateur FreePascal associé à la plateforme de votre machine d'installé.
10102. Vous devez avoir le code source de FreePascal.
11113. Vous devez soit compiler à partir du code source, soit vous procurer des binaires des utilitaires de compilation croisée qui fonctionnent sur la plate-forme où vous compilez et qui sont destinés à compiler des programmes pour la plate-forme cible.
12124. Vous aurez quelquefois besoin de fichiers venant du système cible pour lequel vous compilez.
1313
1414# À partir de Linux
1515
1616## Vers Linux
1717
1818Pour faire simple, il s'agit de compiler de linux(x86_64) à linux(i386).
1919
2020Il est vraisemblable que votre distribution Linux 64 peut déjà compiler des programmes 32 bits, mais en raison de la conception de la construction de fpc, vous pourriez avoir deux ou trois choses à faire.
2121
2222- vérifiez d'abord que vous avez déjà les fichiers i386-linux-ld et i386-linux-as :
2323
24-` bash $ which i386-linux-ld`
24+```text
25+ bash $ which i386-linux-ld
26+```
2527
26-` bash $ which i386-linux-as`
28+```text
29+ bash $ which i386-linux-as
30+```
2731
2832Si vous les avez, passez à "Compiler FPC". N'ayant pas ces fichiers, j'ai écrit ces scripts:
2933
30-`#!/bin/bash`\
31-`# name this file /usr/bin/i386-linux-ld`\
32-`ld -A elf32-i386 $@`
34+```text
35+#!/bin/bash
36+# name this file /usr/bin/i386-linux-ld
37+ld -A elf32-i386 $@
38+```
3339
34-`#!/bin/bash`\
35-`# name this file /usr/bin/i386-linux-as`\
36-`as --32 $@`
40+```text
41+#!/bin/bash
42+# name this file /usr/bin/i386-linux-as
43+as --32 $@
44+```
3745
3846- Les rendre exécutables :
3947
40-`bash $ chmod +x /usr/bin/i386-linux-as`\
41-`bash $ chmod +x /usr/bin/i386-linux-ld`
48+```text
49+bash $ chmod +x /usr/bin/i386-linux-as
50+bash $ chmod +x /usr/bin/i386-linux-ld
51+```
4252
4353- Compiler FPC:
4454
45-`bash $ make all CPU_TARGET=i386`
55+```text
56+bash $ make all CPU_TARGET=i386
57+```
4658
4759puis :
4860
49-`bash $ su -c "make install CPU_TARGET=i386"`
61+```text
62+bash $ su -c "make install CPU_TARGET=i386"
63+```
5064
5165C'est tout. Editez votre fichier /etc/fpc.cfg si nécessaire.
5266
5367## Vers Windows
5468
5569[[Cross compiling for Win32 under Linux/fr|Compilation_croisée_pour_Win32_sous_Linux]]
5670
5771Si vous compilez la branche 2.1.1 ou supérieure de fpc il suffit de faire :
5872
59-`bash $ make all OS_TARGET=win32 CPU_TARGET=i386`
73+```text
74+bash $ make all OS_TARGET=win32 CPU_TARGET=i386
75+```
6076
6177puis
6278
63-`bash $ su -c "make crossinstall OS_TARGET=win32 CPU_TARGET=i386"`
79+```text
80+bash $ su -c "make crossinstall OS_TARGET=win32 CPU_TARGET=i386"
81+```
6482
6583Note : Pour construire pour Win64, la commande make est : make all OS_TARGET=win64 CPU_TARGET=x86_64
6684
6785La raison de cette simplicité est la présence d'un linker interne dans cette version de fpc.
6886
6987## To Darwin or macOS
7088
7189- First you need the binutils for the platform you want to compile to. Download odcctools from this site (use the cvs version) and follow their instructions for installing. <http://www.opendarwin.org/projects/odcctools/>
7290- you need to create a fake root dir like: \$HOME/darwinroot copy at least the /System and /Frameworks and /usr directories (you may have to copy more than this) from your Apple or Darwin computer to \$HOME/darwinroot
7391- now that you have these files make a folder in \$HOME/darwinroot called cross. where ever you installed the odcctools you need to make links for the cross tools to be more fpc friendly. there are a bunch of files from odcc tools called powerpc-apple-darwin-* you need to make links (or rename them) so powerpc-apple-darwin-ld becomes powerpc-darwin-ld, do the same for *-ar and *-as.
7492- now you are ready to crosscompile fpc. basically you need to have the fpc source and have a terminal open there.
7593
7694type:
7795
78-`$PATH=$PATH:$HOME/darwinroot/cross (or whereever you made the symlinks)`
96+```text
97+$PATH=$PATH:$HOME/darwinroot/cross (or whereever you made the symlinks)
98+```
7999
80100type (iirc):
81101
82-`make all TARGET_OS=darwin TARGET_CPU=powerpc OPT="-Xd -Fl/$HOME/darwinroot/usr/lib"`
102+```text
103+make all TARGET_OS=darwin TARGET_CPU=powerpc OPT="-Xd -Fl/$HOME/darwinroot/usr/lib"
104+```
83105
84106if that succeded you can install it to whereever you want with:
85107
86-`make install TARGET_OS=darwin TARGET_CPU=powerpc PREFIX=/cross/fpc`
108+```text
109+make install TARGET_OS=darwin TARGET_CPU=powerpc PREFIX=/cross/fpc
110+```
87111
88112now copy the file ./compiler/ppccross somewhere you will be able to find it as it's the compiler you'll need to build powerpc programs
89113
90114- configure your /etc/fpc.cfg file.
91115
92116add a section like this:
93117
94-`#IFDEF powerpc`\
95-`-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/`\
96-`-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl`\
97-`-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/*`\
98-`-k-systemroot $HOME/darwin/cross`\
99-`#ENDIF`
118+```text
119+#IFDEF powerpc
120+-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/
121+-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
122+-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
123+-k-systemroot $HOME/darwin/cross
124+#ENDIF
125+```
100126
101127whenever you want to crosscompile you have to have ppccross and the symlinks to powerpc-darwin-* in the PATH and you should be able to just do ppccross someprogie.pas and it will create a darwin executable.
102128
103129I may have mistated some things (or most everything) as it's been a while since I did this.
104130
105131# From Windows
106132
107133## To Linux
108134
109135Marco vd Voort wrote some [crossnotes](http://www.stack.nl/~marcov/crossnotes.txt). If somebody has time, he can add them to this wiki.
110136
111137# From Darwin (macOS) i386
112138
113139## from i386 to powerpc
114140
115141- Cross binutils
116142
117143First check if you already have the files powerpc-darwin-ld and powerpc-darwin-as:
118144
119-` $ which powerpc-darwin-ld`\
120-` $ which powerpc-darwin-as`
145+```text
146+ $ which powerpc-darwin-ld
147+ $ which powerpc-darwin-as
148+```
121149
122150If you have these files skip the creation of the symlinks and go to the "Compile FPC" heading.
123151
124152Actually, the "normal" binutils can be used, since they are universal. Therefore, simple symlinks are enough:
125153
126-` $ sudo ln -s /usr/bin/as /usr/bin/powerpc-darwin-as`\
127-` $ sudo ln -s /usr/bin/ld /usr/bin/powerpc-darwin-ld`
154+```text
155+ $ sudo ln -s /usr/bin/as /usr/bin/powerpc-darwin-as
156+ $ sudo ln -s /usr/bin/ld /usr/bin/powerpc-darwin-ld
157+```
128158
129159The symlinks can be in any other directory, as long as it is in your \$PATH (for example /sw/bin when installing through fink).
130160
131161- Compile FPC:
132162
133-` $ cd fpc/compiler`\
134-` $ make cycle CPU_TARGET=powerpc`
163+```text
164+ $ cd fpc/compiler
165+ $ make cycle CPU_TARGET=powerpc
166+```
135167
136168This creates the powerpc compiler (fpc/compiler/ppcppc) and the units of the rtl.
137169
138170In order to create powerpc binaries no actual crosscompiler is needed. The powerpc fpc and ppcppc run fine on IntelMacs using Rosetta.
139171
140172More test and docs are needed for parallel installation of both and usage.
141173
142174If there are missing units, check your config file, \$HOME/.fpc.cfg or /etc/fpc.cfg or /sw/etc/fpc.cfg You may have to add something like or where ever your units are located.
143175
144-`-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/`\
145-`-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl`\
146-`-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/*`
176+```text
177+-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/
178+-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
179+-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
180+```
147181
148182Reminder: Universal binaries are created from the individual (i386 and powerpc) binaries using lipo.
149183
150184## From Darwin to Windows, Linux and others
151185
152186The fpc package of the package manager [fink](http://finkproject.org/) has a 64-bit compiler. In addition, there is a list of packages for crosscompiling to windows, linux, freebsd on various CPUs.
153187
154188Examples for installing a crosscompiler are:
155189
156190``` bash
157191$ fink install fpc-cross-i386-win32
158192```
159193
160194or
161195
162196``` bash
163197$ fink install fpc-cross-arm-linux
164198```
165199
166200To compile use these commands:
167201
168202``` bash
169203fpc -Pi386 -Twin32 FILENAME
170204fpc -Parm -Tlinux FILENAME
171205```
172206
173207This command gives the list of cross compilers:
174208
175209``` bash
176210$ fink list fpc-cross
177211```
178212
179213Currently (fpc 3.0.4), it gives:
180214
181215``` bash
182216fpc-cross-arm-gba
183217fpc-cross-arm-linux
184218fpc-cross-arm-nds
185219fpc-cross-arm-wince
186220fpc-cross-arm-armv4t-embedded
187221fpc-cross-arm-armv7m-embedded
188222fpc-cross-i386-darwin
189223fpc-cross-i386-freebsd
190224fpc-cross-i386-go32v2
191225fpc-cross-i386-linux
192226fpc-cross-i386-nativent
193227fpc-cross-i386-netbsd
194228fpc-cross-i386-solaris
195229fpc-cross-i386-win32
196230fpc-cross-i386-wince
197231fpc-cross-jvm-android
198232fpc-cross-jvm-java
199233fpc-cross-m68k-linux
200234fpc-cross-mipsel-linux
201235fpc-cross-powerpc-linux
202236fpc-cross-sparc-linux
203237fpc-cross-x86-64-dragonfly
204238fpc-cross-x86-64-freebsd
205239fpc-cross-x86-64-linux
206240fpc-cross-x86-64-win64
207241```
208242
209243For other platforms (processors and systems) you have to do the setup by yourself. It is basically the same scheme: First, you need the corresponding binutils (See [[Binutils/fr|Binutils]]) and second, the crosscompiler and the run time library. Some more details of the building procedure can be learned from the fink package description files of the crosscompilers from above.
210244
211245# Cross compile FAQ
212246
213247## Why cross compile?
214248
215249So you can develop a program for one OS/CPU and compile it for another OS/CPU without rebooting or switching computers.
216250
217251## Why Linux to Windows and not the other way around?
218252
219253The main reason for this is that generating unix binaries on a foreign platform (another unix or even Linux distro included) is more complicated. Static linking is already complicated, let alone shared.
220254
221255You would need the used libraries from the target platforms (gtk, glib,libc etc), and a lot of additional configuring for ld. (library paths, dynlinker path, etc.)
222256
223257This has been partially done (for the static case), but it is hard since it needs manual postediting of linker files and linker commandline, and a deep understanding about what makes Unix binaries tick.
224258
225259## I want more information on building Freepascal. Where is it?
226260
227261This is a general FAQ in pdf format about how to build and configure FPC: <http://www.stack.nl/~marcov/buildfaq.pdf>.
228262
229263---
230264*From the Free Pascal wiki, page "Cross compiling/fr", as it stood on 2020-05-03 after a change by E-ric, 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