Sign in Join
Wiki copytemporary

Cross compiling/fr: what changed

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

OldNewLine
1-## Contents
2-
3- * 1 avant-propos
4- * 1.1 Étapes de base
5- * 2 À partir de Linux
6- * 2.1 Vers Linux
7- * 2.2 Vers Windows
8- * 2.3 To Darwin or macOS
9- * 3 From Windows
10- * 3.1 To Linux
11- * 4 From Darwin (macOS) i386
12- * 4.1 from i386 to powerpc
13- * 4.2 From Darwin to Windows, Linux and others
14- * 5 Cross compile FAQ
15- * 5.1 Why cross compile?
16- * 5.2 Why Linux to Windows and not the other way around?
17- * 5.3 I want more information on building Freepascal. Where is it?
18-
191# avant-propos
202
21-Ceci 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à.
3+Ceci 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à.
224
235## Étapes de base
246
25-Il y a plusieurs étapes qui sont obligatoires pour faire de la cross-compilation :
7+Il y a plusieurs étapes qui sont obligatoires pour faire de la cross-compilation :
268
27- 1. Vous devez avoir le compilateur FreePascal associé à la plateforme de votre machine d'installé.
28- 2. Vous devez avoir le code source de FreePascal.
29- 3. 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.
30- 4. Vous aurez quelquefois besoin de fichiers venant du système cible pour lequel vous compilez.
9+1. Vous devez avoir le compilateur FreePascal associé à la plateforme de votre machine d'installé.
10+2. Vous devez avoir le code source de FreePascal.
11+3. 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.
12+4. Vous aurez quelquefois besoin de fichiers venant du système cible pour lequel vous compilez.
3113
3214# À partir de Linux
3315
3416## Vers Linux
3517
36-Pour faire simple, il s'agit de compiler de linux(x86_64) à linux(i386).
18+Pour faire simple, il s'agit de compiler de linux(x86_64) à linux(i386).
3719
38-Il 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.
20+Il 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.
3921
40- * vérifiez d'abord que vous avez déjà les fichiers i386-linux-ld et i386-linux-as :
22+- vérifiez d'abord que vous avez déjà les fichiers i386-linux-ld et i386-linux-as :
4123
42-```
43-bash $ which i386-linux-ld
44-```
45-```
46-bash $ which i386-linux-as
47-```
24+` bash $ which i386-linux-ld`
4825
49-Si vous les avez, passez à "Compiler FPC". N'ayant pas ces fichiers, j'ai écrit ces scripts:
50-```
51-#!/bin/bash
52- # name this file /usr/bin/i386-linux-ld
53- ld -A elf32-i386 $@
54-```
55-```
56-#!/bin/bash
57- # name this file /usr/bin/i386-linux-as
58- as --32 $@
59-```
26+` bash $ which i386-linux-as`
6027
61- * Les rendre exécutables :
28+Si vous les avez, passez à "Compiler FPC". N'ayant pas ces fichiers, j'ai écrit ces scripts:
6229
63-```
64-bash $ chmod +x /usr/bin/i386-linux-as
65- bash $ chmod +x /usr/bin/i386-linux-ld
66-```
30+`#!/bin/bash`\
31+`# name this file /usr/bin/i386-linux-ld`\
32+`ld -A elf32-i386 $@`
6733
68- * Compiler FPC:
34+`#!/bin/bash`\
35+`# name this file /usr/bin/i386-linux-as`\
36+`as --32 $@`
6937
70-```
71-bash $ make all CPU_TARGET=i386
72-```
38+- Les rendre exécutables :
7339
74-puis :
75-```
76-bash $ su -c "make install CPU_TARGET=i386"
77-```
40+`bash $ chmod +x /usr/bin/i386-linux-as`\
41+`bash $ chmod +x /usr/bin/i386-linux-ld`
7842
79-C'est tout. Editez votre fichier /etc/fpc.cfg si nécessaire.
43+- Compiler FPC:
8044
45+`bash $ make all CPU_TARGET=i386`
46+
47+puis :
48+
49+`bash $ su -c "make install CPU_TARGET=i386"`
50+
51+C'est tout. Editez votre fichier /etc/fpc.cfg si nécessaire.
52+
8153## Vers Windows
8254
8355[[Cross compiling for Win32 under Linux/fr|Compilation_croisée_pour_Win32_sous_Linux]]
8456
85-Si vous compilez la branche 2.1.1 ou supérieure de fpc il suffit de faire :
86-```
87-bash $ make all OS_TARGET=win32 CPU_TARGET=i386
88-```
57+Si vous compilez la branche 2.1.1 ou supérieure de fpc il suffit de faire :
8958
90-puis
91-```
92-bash $ su -c "make crossinstall OS_TARGET=win32 CPU_TARGET=i386"
93-```
59+`bash $ make all OS_TARGET=win32 CPU_TARGET=i386`
9460
95-Note : Pour construire pour Win64, la commande make est : make all OS_TARGET=win64 CPU_TARGET=x86_64
61+puis
9662
97-La raison de cette simplicité est la présence d'un linker interne dans cette version de fpc.
63+`bash $ su -c "make crossinstall OS_TARGET=win32 CPU_TARGET=i386"`
9864
65+Note : Pour construire pour Win64, la commande make est : make all OS_TARGET=win64 CPU_TARGET=x86_64
66+
67+La raison de cette simplicité est la présence d'un linker interne dans cette version de fpc.
68+
9969## To Darwin or macOS
10070
101- * 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/>
102- * 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
103- * 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.
104- * now you are ready to crosscompile fpc. basically you need to have the fpc source and have a terminal open there.
71+- 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/>
72+- 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
73+- 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.
74+- now you are ready to crosscompile fpc. basically you need to have the fpc source and have a terminal open there.
10575
106-type:
107-```
108-$PATH=$PATH:$HOME/darwinroot/cross (or whereever you made the symlinks)
109-```
76+type:
11077
111-type (iirc):
112-```
113-make all TARGET_OS=darwin TARGET_CPU=powerpc OPT="-Xd -Fl/$HOME/darwinroot/usr/lib"
114-```
78+`$PATH=$PATH:$HOME/darwinroot/cross (or whereever you made the symlinks)`
11579
116-if that succeded you can install it to whereever you want with:
117-```
118-make install TARGET_OS=darwin TARGET_CPU=powerpc PREFIX=/cross/fpc
119-```
80+type (iirc):
12081
121-now 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
82+`make all TARGET_OS=darwin TARGET_CPU=powerpc OPT="-Xd -Fl/$HOME/darwinroot/usr/lib"`
12283
123- * configure your /etc/fpc.cfg file.
84+if that succeded you can install it to whereever you want with:
12485
125-add a section like this:
126-```
127-#IFDEF powerpc
128- -Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/
129- -Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
130- -Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
131- -k-systemroot $HOME/darwin/cross
132- #ENDIF
133-```
86+`make install TARGET_OS=darwin TARGET_CPU=powerpc PREFIX=/cross/fpc`
13487
135-whenever 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.
88+now 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
13689
137-I may have mistated some things (or most everything) as it's been a while since I did this.
90+- configure your /etc/fpc.cfg file.
13891
92+add a section like this:
93+
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`
100+
101+whenever 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.
102+
103+I may have mistated some things (or most everything) as it's been a while since I did this.
104+
139105# From Windows
140106
141107## To Linux
142108
143-Marco vd Voort wrote some [crossnotes](<http://www.stack.nl/~marcov/crossnotes.txt>). If somebody has time, he can add them to this wiki.
109+Marco vd Voort wrote some [crossnotes](http://www.stack.nl/~marcov/crossnotes.txt). If somebody has time, he can add them to this wiki.
144110
145111# From Darwin (macOS) i386
146112
147113## from i386 to powerpc
148114
149- * Cross binutils
115+- Cross binutils
150116
151-First check if you already have the files powerpc-darwin-ld and powerpc-darwin-as:
152-```
153-$ which powerpc-darwin-ld
154- $ which powerpc-darwin-as
155-```
117+First check if you already have the files powerpc-darwin-ld and powerpc-darwin-as:
156118
157-If you have these files skip the creation of the symlinks and go to the "Compile FPC" heading.
119+` $ which powerpc-darwin-ld`\
120+` $ which powerpc-darwin-as`
158121
159-Actually, the "normal" binutils can be used, since they are universal. Therefore, simple symlinks are enough:
160-```
161-$ sudo ln -s /usr/bin/as /usr/bin/powerpc-darwin-as
162- $ sudo ln -s /usr/bin/ld /usr/bin/powerpc-darwin-ld
163-```
122+If you have these files skip the creation of the symlinks and go to the "Compile FPC" heading.
164123
165-The symlinks can be in any other directory, as long as it is in your $PATH (for example /sw/bin when installing through fink).
124+Actually, the "normal" binutils can be used, since they are universal. Therefore, simple symlinks are enough:
166125
167- * Compile FPC:
126+` $ sudo ln -s /usr/bin/as /usr/bin/powerpc-darwin-as`\
127+` $ sudo ln -s /usr/bin/ld /usr/bin/powerpc-darwin-ld`
168128
169-```
170-$ cd fpc/compiler
171- $ make cycle CPU_TARGET=powerpc
172-```
129+The symlinks can be in any other directory, as long as it is in your \$PATH (for example /sw/bin when installing through fink).
173130
174-This creates the powerpc compiler (fpc/compiler/ppcppc) and the units of the rtl.
131+- Compile FPC:
175132
176-In order to create powerpc binaries no actual crosscompiler is needed. The powerpc fpc and ppcppc run fine on IntelMacs using Rosetta.
133+` $ cd fpc/compiler`\
134+` $ make cycle CPU_TARGET=powerpc`
177135
178-More test and docs are needed for parallel installation of both and usage.
136+This creates the powerpc compiler (fpc/compiler/ppcppc) and the units of the rtl.
179137
180-If 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.
181-```
182--Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/
183- -Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
184- -Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
185-```
138+In order to create powerpc binaries no actual crosscompiler is needed. The powerpc fpc and ppcppc run fine on IntelMacs using Rosetta.
186139
187-Reminder: Universal binaries are created from the individual (i386 and powerpc) binaries using lipo.
140+More test and docs are needed for parallel installation of both and usage.
188141
142+If 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.
143+
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/*`
147+
148+Reminder: Universal binaries are created from the individual (i386 and powerpc) binaries using lipo.
149+
189150## From Darwin to Windows, Linux and others
190151
191-The 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.
152+The 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.
192153
193-Examples for installing a crosscompiler are:
194-```
154+Examples for installing a crosscompiler are:
155+
156+``` bash
195157$ fink install fpc-cross-i386-win32
196158```
197159
198-or
199-```
160+or
161+
162+``` bash
200163$ fink install fpc-cross-arm-linux
201164```
202165
203-To compile use these commands:
204-```
166+To compile use these commands:
167+
168+``` bash
205169fpc -Pi386 -Twin32 FILENAME
206- fpc -Parm -Tlinux FILENAME
170+fpc -Parm -Tlinux FILENAME
207171```
208172
209-This command gives the list of cross compilers:
210-```
173+This command gives the list of cross compilers:
174+
175+``` bash
211176$ fink list fpc-cross
212177```
213178
214-Currently (fpc 3.0.4), it gives:
215-```
179+Currently (fpc 3.0.4), it gives:
180+
181+``` bash
216182fpc-cross-arm-gba
217- fpc-cross-arm-linux
218- fpc-cross-arm-nds
219- fpc-cross-arm-wince
220- fpc-cross-arm-armv4t-embedded
221- fpc-cross-arm-armv7m-embedded
222- fpc-cross-i386-darwin
223- fpc-cross-i386-freebsd
224- fpc-cross-i386-go32v2
225- fpc-cross-i386-linux
226- fpc-cross-i386-nativent
227- fpc-cross-i386-netbsd
228- fpc-cross-i386-solaris
229- fpc-cross-i386-win32
230- fpc-cross-i386-wince
231- fpc-cross-jvm-android
232- fpc-cross-jvm-java
233- fpc-cross-m68k-linux
234- fpc-cross-mipsel-linux
235- fpc-cross-powerpc-linux
236- fpc-cross-sparc-linux
237- fpc-cross-x86-64-dragonfly
238- fpc-cross-x86-64-freebsd
239- fpc-cross-x86-64-linux
240- fpc-cross-x86-64-win64
183+fpc-cross-arm-linux
184+fpc-cross-arm-nds
185+fpc-cross-arm-wince
186+fpc-cross-arm-armv4t-embedded
187+fpc-cross-arm-armv7m-embedded
188+fpc-cross-i386-darwin
189+fpc-cross-i386-freebsd
190+fpc-cross-i386-go32v2
191+fpc-cross-i386-linux
192+fpc-cross-i386-nativent
193+fpc-cross-i386-netbsd
194+fpc-cross-i386-solaris
195+fpc-cross-i386-win32
196+fpc-cross-i386-wince
197+fpc-cross-jvm-android
198+fpc-cross-jvm-java
199+fpc-cross-m68k-linux
200+fpc-cross-mipsel-linux
201+fpc-cross-powerpc-linux
202+fpc-cross-sparc-linux
203+fpc-cross-x86-64-dragonfly
204+fpc-cross-x86-64-freebsd
205+fpc-cross-x86-64-linux
206+fpc-cross-x86-64-win64
241207```
242208
243-For 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.
209+For 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.
244210
245211# Cross compile FAQ
246212
247213## Why cross compile?
248214
249-So you can develop a program for one OS/CPU and compile it for another OS/CPU without rebooting or switching computers.
215+So you can develop a program for one OS/CPU and compile it for another OS/CPU without rebooting or switching computers.
250216
251217## Why Linux to Windows and not the other way around?
252218
253-The 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.
219+The 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.
254220
255-You 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.)
221+You 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.)
256222
257-This 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.
223+This 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.
258224
259225## I want more information on building Freepascal. Where is it?
260226
261227This is a general FAQ in pdf format about how to build and configure FPC: <http://www.stack.nl/~marcov/buildfaq.pdf>.
262228
263229---
264-*From the Free Pascal wiki, page "Cross compiling/fr", as the Internet Archive kept it on 2025-03-27. 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).*
230+*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