Sign in Join
Wiki copytemporary

Installing the Free Pascal Compiler: what changed

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

Title: Installing the Free Pascal Compiler

OldNewLine
1+While the Free Pascal Compiler comes pre-built for several processor architectures and operating systems, there may be occasions where a pre-built compiler won't do, and you need to build it yourself. There are a number of reasons for doing this, including:
2+
3+- Intellectual curiosity - you want to discover the compiler's speed, using a medium sized application like the compiler itself.
4+- Cross Compiling - you want to build a compiler that creates binaries for a different CPU architecture, operating environment, or both, than the one you are using right now.
5+- New environment - you want to build the compiler for a processor or operating system that either a version of the compiler does not currently exist, or you are porting it to a new operating system or processor.
6+- Do it yourself - you prefer to build applications from source where possible.
7+- Security - for organizational policy, legal requirements, or operational security, programs from untrusted sources cannot be used, and must be recompiled locally. Or you want to confirm the compiler you have is the same as the one it produces, possibly running a checksum on the new one to confirm it matches the published one.
8+
9+And the most obvious reason of all:
10+
11+- New Version - you are creating a new release of the compiler.
12+
13+This document will try to help you do these things.
14+
15+## Overview
16+
17+There are a number of ways to install the Free Pascal Compiler and its libraries on your system. The current version and trunk, and sometimes beta and release candidates, are available directly from the [FPC website](https://sourceforge.net/projects/freepascal/files/) (tar, exe, rpm, dmg, pkg files). In addition, versions of FPC are provided (including rpm and deb files) from the [Lazarus download site](http://sourceforge.net/projects/lazarus/files/). Linux users can almost certainly find FPC in their distribution's repositories but may find that it is outdated.
18+
19+It is possible to build FPC from source, typically each release needs to be built with the previous release. It is possible to install FPC in the application space (often requiring root or administrator access) or in a your own user space. These things depend on your particular operating system.
20+
21+There is an extensive discussion of how to install and build Free Pascal compilers available here <http://www.stack.nl/~marcov/buildfaq.pdf> - it may be a little too detailed for some users, but it is very comprehensive.
22+
23+## Linux
24+
25+### Downloading FPC binary packages
26+
27+> **Note:** You have a number of way to install FPC presented here, which one is best for you depends very much on what you are planning to do and if you need a very current version. If you are also planning on installing Lazarus, perhaps a quick look at [[Installing Lazarus]] and [[Installing Lazarus on Linux]] is a very good idea.
28+
29+With the recent release of FPC 3.2.2, only a few distributions will have the new FPC compiler in its repositories. You can do one of -
30+
31+- If you use **rpm packages**, you can find FPC322 in <https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/> or more generally in <https://www.freepascal.org/download.html> You might install using a command like -
32+
33+// or perhaps rpm -Uvh fpc-3.2.2-1.x86_64.rpm
34+
35+</syntaxhighlight>
36+
37+- If you use **deb packages** try the ones made available by, but not bundled with Lazarus at <https://sourceforge.net/projects/lazarus/files/>. Install using gdebi or, perhaps this command (note the ./ in front of filename, if you don't use an explicit path to filename, apt will search its own official repo, not what you want)-
38+ ``` bash
39+ apt install ./fpc-laz_3.2.2-1_amd64.deb
40+ ```
41+
42+ Note the actual name changes from time to time, use the name you downloaded !
43+
44+If you already have a FPC installed from your distro package manager, you should use that same package manager to remove them before installing under another model. Some quite strange things can happen if your compile uses a mixture of FPC versions !
45+
46+### Downloading FPC tar balls
47+
48+Another option is installing from a tar, an easy and possibly even more useful model. These tars are available for a wide range of Unix like systems. You need to download the appropriate binary tar for your OS and CPU and you may also need the source files, common for all OS/CPU. You install FPC this way in your own space, not as root.
49+
50+Here is a series of commands, not a script, that will install FPC on a 64 bit Linux system. It could be scripted but would would need sanity and error checking. Note that I like to install things like this in my \$HOME/bin directory, if you prefer having it in \$HOME, it is even easier, I am sure you can see the differences.
51+
52+> **Note:** A tar install **does not resolve dependencies**, if they are not already present, first install binutils, make, gcc.
53+
54+> **Note:** A tar ball install will, if you manage paths properly, allow you to have several versions of FPC installed.
55+
56+(if you want something a bit newer, please see <https://www.freepascal.org/develop.html> )
57+
58+``` bash
59+cd
60+mkdir -p bin/FPC/Tars
61+mkdir bin/FPC/SRC
62+mkdir bin/FPC/fpc-3.2.2
63+cd bin/FPC/Tars
64+# download src and compiler tars, change for different CPU (or Mac ?)
65+
66+wget https://sourceforge.net/projects/freepascal/files/Source/3.2.2/fpc-3.2.2.source.tar.gz
67+wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/fpc-3.2.2.x86_64-linux.tar
68+
69+tar xf fpc-3.2.2.x86_64-linux.tar
70+cd fpc-3.2.2.x86_64-linux
71+./install.sh
72+# when asked where to install, enter $HOME/bin/FPC/fpc-3.2.2, accept all defaults after that.
73+
74+cd ../../SRC
75+tar xzf ../Tars/fpc-3.2.2.source.tar.gz
76+
77+# Set a path to where the compiler is, add line at end of .bashrc, if you don't use bash, adjust !
78+# (! e.g. Use ~/.profile instead of ~/.bashrc so that the path is available also in Lazarus IDE.)
79+echo "PATH=\"\$HOME/bin/FPC/fpc-3.2.2/bin\":\"\$PATH\"" >> ~/.bashrc
80+source ~/.bashrc
81+
82+# trivial test
83+cd
84+fpc -iV
85+```
86+
87+> **Note:** The second wget above assumes you are working with an amd64 (AMD or Intel) type machine, other platforms require a different tar ball. For example, for a **Raspberry Pi**, you would use -
88+>
89+> ``` bash
90+> wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/fpc-3.2.2.arm-linux.tar
91+> ```
92+>
93+> which has the armhf 32bit compiler. Incidentally, the Raspberry Pi may need you to increase swap space to at least a Gig if you plan to later build any large applications with FPC.
94+
95+### Downloading FPC sources from Git or zip
96+
97+If you plan to build your own compiler from source, this is the approach for you.
98+
99+The FPC source files are stored in a git repository (https://gitlab.com/freepascal.org/fpc/source). The repository keeps track of all the changes by developers in the source tree and has multiple branches. Once you have the sources, please see Installing from source under BSD/Linux for instructions on how to install them.
100+
101+Anyone can download (but not upload) the source using either git or, easier if you want a one off snapshot, zip. And possibly even SVN. The default is to get the main (aka trunk) version of the source but you also select any one of the very many branches or tags.
102+
103+**Git** - is most appropriate if you are going to add or sorrect something in the source and submit your change to the developers. Its a bigger and slower download but once done, easy to keep up to date. Note that its very unlikely contributions to anything other than main will be accepted. Here is an example initial download of main, assuming you already have git installed -
104+
105+`git clone `[`https://gitlab.com/freepascal.org/fpc/source`](https://gitlab.com/freepascal.org/fpc/source)
106+
107+Once the git download is finished, cd into the new directory and build as documented below. You can now keep your git repository up to date using the normal git commands. Git is well documented online but (https://wiki.freepascal.org/FPC_git) has some fpc specific help.
108+
109+**Zip** - a possibly easier option is to download a "zip ball' archive of the source, from the web interface you can select which branch or tag you are interested in (combo box that defaults to 'main'). There are quite a lot of branches and tags to choose from, so please choose carefully. The web interface will let you download the zip of the selected branch or tag directly or command line people may do one of (with the last part of command line indicating which branch):
110+
111+`wget `[`https://gitlab.com/freepascal.org/fpc/source/-/archive/fixes_3_2/source-fixes_3_2.zip`](https://gitlab.com/freepascal.org/fpc/source/-/archive/fixes_3_2/source-fixes_3_2.zip)\
112+`wget `[`https://gitlab.com/freepascal.org/fpc/source/-/archive/release_3_2_2/source-release_3_2_2.zip`](https://gitlab.com/freepascal.org/fpc/source/-/archive/release_3_2_2/source-release_3_2_2.zip)
113+
114+You would unzip the zipball and build the source as described below.
115+
116+#### Documentation sources
117+
118+The documentation sources are in a separate repository called fpcdocs, so the command to get them is:
119+
120+``` bash
121+cd ~
122+git clone https://gitlab.com/freepascal.org/fpc/documentation.git fpcdocs
123+```
124+
125+If you want to learn more about subversion, read this excellent [Subversion book](http://svnbook.red-bean.com/) which is also available online in different formats for free.
126+
127+For more information, see the [Free Pascal website](https://www.freepascal.org/develop.html).
128+
129+### Compiling the FPC source, using preinstalled FPC
130+
131+- First install the release FPC from RPM/DEB or tarballs as described above.
132+- Get FPC sources (trunk) as described above.
133+- Make FPC sources with (execute in the source (trunk) directory):
134+
135+``` bash
136+make clean
137+make all
138+make install INSTALL_PREFIX=install/to/directory
139+```
140+
141+Decide about install/to/directory and also add options that you need.
142+
143+- Check your ~/.fpc.cfg or /etc/fpc.cfg. It either has to be valid for the trunk compiler as well or you have to move it to the ../etc directory above your compiler executable. E.g. if your compiler is in ~/software/fpc/3.2.0/lib/fpc/3.2.0 (~/software/fpc/3.2.0/bin), you have to move the fpc.cfg to ~/software/fpc/3.2.0/lib/fpc/etc.
144+- If you have no valid global fpc.cfg file, you have to create one in install/to/directory/lib/fpc/etc. For this run the following commands
145+
146+``` bash
147+cd install/to/directory/lib/fpc
148+mkdir etc
149+fpcmkcfg -d basepath="install/to/directory/lib/fpc/\$fpcversion" -o etc/fpc.cfg
150+```
151+
152+### Compiling the FPC source, using just downloaded FPC 3.2.2
153+
154+- Download FPC 3.2.2 (latest official release), ie tarball fpc-3.2.2.x86_64-linux.tar.
155+- Unpack this tarball to e.g. "~/Downloads/fpc", do CD to the folder containing the file "install.sh", run from Terminal:
156+
157+`$ ./install.sh`
158+
159+It will ask several questions in the Terminal, answer them. You will have installed FPC 3.2.2 to the folder e.g. "/home/user/fpc-3.2.2".
160+
161+- Download the Git snapshot of FPC:
162+
163+`$ git clone `[`https://gitlab.com/freepascal.org/fpc/source`](https://gitlab.com/freepascal.org/fpc/source)
164+
165+- Do CD to new folder "source" and call:
166+
167+`$ make clean PP=/home/user/fpc-3.2.2/bin/fpc`\
168+`$ make all PP=/home/user/fpc-3.2.2/bin/fpc`
169+
170+Here you must specify the "PP=" key and the full path to the "fpc" file installed from tarball. Command "make clean" is required if you **compile again**.
171+
172+Final compiled binary will be the file "source/compiler/ppcx64".
173+
174+## FreeBSD
175+
176+> **Note:** If you wish to also install Lazarus, you can omit installing FPC with the steps below as the Lazarus port will install it for you. See [[Installing Lazarus on FreeBSD]].
177+
178+### Installing from the ports collection
179+
180+The FreeBSD ports collection has FPC v3.2.2 version in `/usr/ports/lang/fpc` and FPC Development v3.3.1 version in `/usr/ports/lang/fpc-devel`. Nowadays all units were merged into only one package of FPC/FPC-devel. The FPC/FPC-devel source is now installed by default; it previously needed to be copied and uncompressed from `/usr/ports/distfiles/freepascal`.
181+
182+This must be done as root.
183+
184+``` bash
185+# cd /usr/ports/lang/fpc && make install && make clean
186+```
187+
188+If you want use development (aka trunk) version of fpc with all units included do the following:
189+
190+``` bash
191+# cd /usr/ports/lang/fpc-devel && make install clean
192+```
193+
194+Also, you can install FPC and units from pkg binaries:
195+
196+``` bash
197+# pkg install lang/fpc
198+```
199+
200+Installing development FPC and units from pkg binaries:
201+
202+``` bash
203+# pkg install lang/fpc-devel
204+```
205+
206+Once FPC is installed you can check if it's working by simply running as a normal user:
207+
208+``` bash
209+$ fpc test
210+```
211+
212+which should produce output similar to this:
213+
214+` Free Pascal Compiler version 3.2.2 [2021/08/03] for x86_64`\
215+` Copyright (c) 1993-2021 by Florian Klaempfl and others`\
216+` Target OS: FreeBSD for x86-64`\
217+` Compiling test`\
218+` Fatal: Cannot open file "test"`\
219+` Fatal: Compilation aborted`\
220+` Error: /usr/local/bin/ppcx64 returned an error exitcode`
221+
222+### Installing from tar
223+
224+Select the appropriate 32 bit/64 bit tar file based on your system. For x86_64 64-bit FreeBSD, download from [x86_64](https://www.freepascal.org/down/x86_64/freebsd.html). For i386 32-bit FreeBSD, download from [i386](https://www.freepascal.org/down/i386/freebsd.html).
225+
226+To install Free Pascal from a terminal:
227+
228+``` bash
229+$ fetch ftp://ftp.freepascal.org/pub/fpc/dist/3.2.2/x86_64-freebsd/fpc-3.2.2.x86_64-freebsd11.tar
230+$ tar -xf fpc-3.2.2.x86_64-freebsd11.tar
231+$ cd fpc-3.2.2.x86_64-freebsd
232+$ bash install.sh
233+```
234+
235+Replace the desired Free Pascal version (3.0.4, 3.2.0 or 3.2.2) and architecture (x86_64 or i386) as required.
236+
237+If you want to install the Free Pascal Compiler globally, for example in `/usr/local`, run the install.sh script as root. `install.sh` script uses bash shell syntax. If you get `Bad substitution` error, make sure you run script with bash.
238+
239+If you are on FreeBSD 12 or newer, the default linker is the `lld`. This may cause problems if you have code that uses, for example, the *cthreads* unit as in the following program:
240+
241+``` pascal
242+uses cthreads;
243+begin
244+ writeln('hello');
245+end.
246+```
247+
248+The executable generated for this program will cause a segmentation fault when run. To fix this issue, you need to install the GNU linker:
249+
250+``` bash
251+root# pkg install binutils
252+```
253+
254+and add a symbolic-link from `/usr/local/bin/ld.bfd` to `/bin/ld.bfd`.
255+
256+## OpenBSD
257+
258+### Installing from tar
259+
260+Select the appropriate 32 bit/64 bit tar file based on your system. For x86_64 64-bit OpenBSD, download from [x86_64](https://sourceforge.net/projects/freepascal/files/OpenBSD/3.2.2/fpc-3.2.2.x86_64-openbsd.tar). For i386 32-bit OpenBSD, download from [i386](https://sourceforge.net/projects/freepascal/files/OpenBSD/3.2.2/fpc-3.2.2.i386-openbsd.tar).
261+
262+To install Free Pascal from a terminal:
263+
264+``` bash
265+$ wget https://sourceforge.net/projects/freepascal/files/OpenBSD/3.2.2/fpc-3.2.2.x86_64-openbsd.tar
266+$ tar -xf fpc-3.2.2.x86_64-openbsd.tar
267+$ cd fpc-3.2.2.x86_64-openbsd
268+$ bash install.sh
269+```
270+
271+Replace the desired Free Pascal version (3.0.4, 3.2.0, or 3.2.2) and architecture (x86_64 or i386) as required.
272+
273+If you want to install the Free Pascal Compiler globally, for example in `/usr/local`, run the install.sh script as root. `install.sh` script uses bash shell syntax. If you get `Bad subtitution` error, make sure you run script with bash. OpenBSD uses ksh as default shell. You need to install bash manually.
274+
275+## Installing from source on BSD/Linux
276+
277+Effectively, you need:
278+
279+1\. A file with all FPC sources downloaded from git (https://gitlab.com/freepascal.org/fpc/source) or perhaps (https://sourceforge.net/projects/freepascal/files/Source/3.2.2/fpc-3.2.2.source.tar.gz).
280+
281+2\. A starting (bootstrap) FPC compiler. An FPC release can always be built by the previously released FPC version, and FPC trunk can always be built by the current FPC release. You can download a bootstrap Free Pascal Compiler or use your distribution's package management/software system to install one.
282+
283+FPC build process:
284+
285+- Fetch necessary files (starting compiler), FPC source file or source svn directory
286+- If using FPC source files: extract/de-tgz in work directory,
287+- Build: enter work/fpc/ and run:
288+
289+``` bash
290+# Linux use:
291+export MAKE=`which make` ; echo $MAKE
292+# FreeBSD use (default csh, or tcsh):
293+set MAKE=`which gmake` ; echo $MAKE
294+# FreeBSD use (bash):
295+export MAKE=`which gmake` ; echo $MAKE
296+$MAKE all OPT='-gl' FPC=/path/to/startingcompiler-name-ppcx64
297+# $MAKE is make on Linux and gmake on BSD
298+# /path/to/ can be omitted when ppc386 (32 bit) or ppcx64 (64 bit) is in the path
299+```
300+
301+- Install FPC. Again in work/fpc, run
302+
303+``` bash
304+$MAKE install FPC=compiler/ppcx64 PREFIX=$THEPREFIX
305+#replace the FPC=compiler/ppcx64 (or ppc386 for 32 bit) with the relevant compiler if not on Intel x86
306+#THEPREFIX= usually is /usr/local or just /usr, but eg on NetBSD it is /usr/pkg for ports)
307+```
308+
309+- Create a symlink:
310+
311+``` bash
312+ln -s $THEPREFIX/lib/fpc/3.2.2/ppcx64 $THEPREFIX/bin/ppcx64
313+```
314+
315+- Install sources:
316+
317+``` bash
318+$MAKE install sourceinstall PREFIX=$THEPREFIX
319+```
320+
321+- Create a symlink for default FPC source path:
322+
323+``` bash
324+ln -sf $THEPREFIX/share/src/3.2.2/fpc /usr/share/fpcsrc
325+```
326+
327+- Set up fpc.cfg configuration file:
328+
329+``` bash
330+$THEPREFIX/lib/fpc/3.2.2/samplecfg $THEPREFIX/lib/fpc/3.2.0 $ETCDIR
331+```
332+
333+- Optionally test to see if `ppcx64 -i` (or whatever compiler your architecture uses) gives output, else give a warning that user needs to add \$PREFIX/bin to the current path. Try to compile a program with `ppcx64 -viwn`, and see if that gives errors.
334+
335+Notes:
336+
337+- If you need fpcmake package lists, you need to generate or supply them yourself, (in the port, or in an extra archive) either way, do a dummy install to /tmp/pack and determine the files installed with
338+ ``` bash
339+ find . >ll
340+ ```
341+
342+- \$THEPREFIX and \$ETCDIR should be user configurable. Otherwise local installs aren't possible.
343+
344+- BSDHIER=1 on all make commands forces BSD hierarchy conventions.
345+
346+## Windows
347+
348+### Installing an FPC release with the Windows installer
349+
350+> **Warning:** If you are intending to also install Lazarus using the official Windows installer which installs both FPC + Lazarus, please ignore these instructions and instead refer to [[Installing Lazarus on Windows]] to avoid having to resolve any resulting conflicts.
351+
352+By far the easiest way to get a working installation of the Free Pascal Compiler is to download and run the appropriate self-extracting Windows installer from the official [SourceForge repository for FPC 3.2.2](https://sourceforge.net/projects/freepascal/files/Win32/3.2.2/) - this release contains the current release versions of the Free Pascal Compiler and the Free Pascal libraries. The Windows installer packages install very easily, and should work 'out-of-the-box'. You will be taken through a typical Windows installation wizard to install the FPC binaries and Free Pascal libraries:
353+
354+- Choose an installation location for FPC (suggested `C:\FPC\3.2.2`)
355+- Choose installation type (recommended Full Installation)
356+- Choose file associations, configuration file creation etc
357+- Install
358+- View README
359+
360+### Installing from source
361+
362+Installing from source with a command line git client is not for novices, since you also need a working bootstrap compiler to be able to compile the Free Pascal Compiler from source. Instructions for obtaining a bootstrap compiler are included below.
363+
364+#### Obtaining the source with a command line git client
365+
366+The easiest way to get the Free Pascal Compiler source is by using a git client. The exact commands may vary between git clients; the commands given below are for the command line git client downloadable from [GitForWindows.org](https://gitforwindows.org/).
367+
368+##### Source for a release version of FPC
369+
370+First create a directory in which you'd like to keep the source. Any normal user can do this. Create a directory for FPC (eg `C:\Source`) by typing the following at a command prompt:
371+
372+```dos
373+C:\Users\you> cd \
374+C:\> mkdir Source
375+C:\> cd Source
376+```
377+
378+Now type issue the following command at a command prompt:
379+
380+```dos
381+C:\Source> git clone -b release_3_2_2 https://gitlab.com/freepascal.org/fpc/source.git fpc-3.2.2
382+```
383+
384+Wait while the git repository is downloaded to the fpc-3.2.2 directory in your newly created Source directory. This can take a while... have a look at the helpful [Free Pascal Forums](https://forum.lazarus.freepascal.org/) while you wait :-) You may also like to read the excellent [[Forum|How to use the Forum]] Wiki article which explains how to get answers to pesky questions quickly. New Forum users are always welcome.
385+
386+##### Source for a non-release version of FPC
387+
388+There are two current non-release branches of the Free Pascal Compiler: the development (main) branch and the Fixes 3.2 branch which includes additional fixes to the released 3.2.2 version. Developers, and those who like living on the bleeding edge and testing new features and fixes, will choose the development version; more normal users, who wish to use a stable branch with some additional fixes since the latest release version, will choose the Fixes branch. The instructions below cover both these branches.
389+
390+If it does not already exist, create a directory in which you'd like to keep the FPC source (eg `C:\Source`). Any normal user can do this. Now type the following command at a command prompt:
391+
392+*For the Fixes branch of FPC 3.2*
393+
394+```dos
395+C:\Source> git clone -b fixes_3_2 https://gitlab.com/freepascal.org/fpc/source.git fpc-fixes-3.2.0
396+```
397+
398+*For the Development (main) branch of FPC*
399+
400+```dos
401+C:\Source> git clone -b main https://gitlab.com/freepascal.org/fpc/source.git fpc-main
402+```
403+
404+Hint: To update your local copy of the repository with subsequent changes, you need only do:
405+
406+*For the Fixes branch of FPC 3.2*
407+
408+```dos
409+C:\> cd C:\Source\fpc-fixes-3.2
410+C:\Source\fpc-fixes-3.2> git clean -f -d
411+C:\Source\fpc-fixes-3.2> git pull
412+```
413+
414+*For the Development (main) branch of FPC*
415+
416+```dos
417+C:\> cd C:\Source\fpc-main
418+C:\Source\fpc-trunk> git clean -f -d
419+C:\Source\fpc-trunk> git pull
420+```
421+
422+#### Obtaining a bootstrap compiler
423+
424+To obtain a bootstrap Free Pascal Compiler, download the distribution package [fpc-3.2.2.i386-win32.exe](https://www.freepascal.org/down/i386/win32.html) and run it - it is a self-extracting installer, so just follow the instructions to install it. The installer should set the PATH environment variable as appropriate.
425+
426+Then restart windows.
427+
428+#### Compiling the FPC source
429+
430+**Before you start**
431+
432+- The installation PREFIX in the instructions that follow is totally dependent on the directory in which you installed FPC. The Windows FPC installer uses a default location of `C:\FPC` and the FPC 3.2.2 release files are placed in `C:\FPC\3.2.2`. Since versions change relatively frequently, it is recommended that you just select and maintain a single PREFIX default location without any regard to FPC version numbers. A reasonable PREFIX to adopt is the one used by the Windows FPC installer (`C:\FPC`) but you must also make sure that the `C:\FPC\bin\i386-win32\` directory is added to your path environment variable.
433+
434+- Check that the `make.exe` which is found first in your path environment variable is the GNU one included with your bootstrap FPC compiler. If you have a recent version of Delphi installed, watch out for its version of `make` being earlier in your path. It does not understand the FPC Makefile and you will receive many errors if you try to use it. You can check this by opening a command prompt and typing `make -v`. The result should be (or very similar):
435+
436+` `![`fpc_windows_make.png`](/wiki-images/1/12/Fpc_windows_make.png)
437+
438+- If you need to change your path so that the correct `make.exe` is found, you can either do it temporarily or permanently.
439+ - To change it temporarily (it is in effect only until you close the current command prompt) to find `make.exe` in `C:\FPC\3.2.2\bin\i386-win32`, at a command prompt type:
440+
441+C:\Source\> set PATH=C:\FPC\3.2.2\bin\i386-win32;%PATH%
442+
443+</syntaxhighlight>
444+
445+- - To change it permanently, open Control Panel \> System and choose "Advanced system settings" under "Related settings" towards the bottom of the page. Now choose "Environment Variables..." in the System Properties dialog. Here you will probably need to change the Path that appears under "System variables" so that `C:\FPC\3.2.2\bin\i386-win32` occurs first.
446+
447+**Instructions**
448+
449+- At a command prompt, navigate to your local FPC source directory (eg `C:\Source\fpc-3.2.2`) by typing:
450+
451+```dos
452+C:\> cd Source\fpc-3.2.2
453+```
454+
455+- Compile the FPC source with:
456+
457+```dos
458+C:/Source/fpc-3.2.2> make distclean all
459+```
460+
461+- To overwrite an existing FPC installation in, for example, `C:\FPC`) type:
462+
463+```dos
464+C:/Source/fpc-3.2.2> make install PREFIX=C:\FPC
465+```
466+
467+- If you also need the cross-compiler to x86_64, type the following commands which will compile the cross-compiler and then install it:
468+
469+```dos
470+C:/Source/fpc-3.2.2> make all OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=C:\FPC\3.2.2 PP=C:\FPC\3.2.2\bin\i386-win32\ppc386.exe DATA2INC=C:\FPC\3.2.2\bin\i386-win32\data2inc.exe
471+
472+C:/Source/fpc-3.2.2> make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=C:\FPC\3.2.2 PP=C:\FPC\3.2.2\bin\i386-win32\ppc386.exe DATA2INC=C:\FPC\3.2.2\bin\i386\win32\data2inc.exe
473+```
474+
475+The cross-compiler to compile programs for Windows 64 bit may now be found here: `C:\FPC\3.2.2\bin\i386-win32\ppcrossx64`.
476+
477+Done!
478+
479+## macOS
480+
481+> **Warning:** If you are intending to also install Lazarus using the official macOS installation packages which install both FPC + Lazarus, please ignore these instructions and instead refer to [[Installing Lazarus on macOS]] to avoid having to resolve any resulting FPC conflicts.
482+
483+### Installing an FPC release from the official macOS packages
484+
485+#### Step 1: Download Xcode (optional)
486+
487+Xcode is a 12GB download which will take up 16GB of disk space. You **only** need to download and install the full Xcode development environment **if** you need:
488+
489+- the SDKs for **iOS**, **iPadOS**, watchOS and tvOS; or
490+- to validate and upload apps to the Mac App Store; or
491+- to [[Notarization for macOS 10.14.5+|notarise]] apps for distribution outside of the Mac App Store.
492+
493+Xcode 11.3.1 for use on macOS 10.14 Mojave must now be installed by downloading it from [Apple Developer Connection](http://developer.apple.com/) (ADC), which requires free registration. Xcode 11.4.x for use on macOS 10.15 Catalina can be installed from the [Mac App store](https://apps.apple.com/us/genre/mac-developer-tools/id12002?mt=12). Note that you must first move any old Xcode versions from the Applications folder into the trash or rename the Xcode app (eg Xcode.app to Xcode_1014.app). You can select which version of Xcode to use with the command line utility `xcode-select`.
494+
495+Older systems:
496+
497+The developer tools can be installed from the original macOS installation disks or a newer copy downloaded from the [Apple Developer Connection](http://developer.apple.com/) (ADC), which requires free registration. Download the Xcode file, it will end up in your Downloads directory as a zip file. Click it. It is unarchived into your Downloads directory. You may be happy with it there but maybe not. Other users will see the path to it but be unable to use it. And it is untidy there. So I moved mine and then told xcode-select where it was moved to (in a terminal) -
498+
499+``` bash
500+mv Downloads/Xcode.app /Developer/.
501+sudo xcode-select -s /Developer/Xcode.app/Contents/Developer
502+```
503+
504+#### Step 2: Xcode Command Line Tools
505+
506+This is shown here as a separate step because it really is a separate step in addition to Step 1. Don't confuse this with the internal Xcode command line tools that the Xcode GUI will tell you are already installed. FPC does not use those Xcode internal command line tools, so do the following (it is quick and easy)-
507+
508+``` bash
509+sudo xcode-select --install
510+sudo xcodebuild -license accept
511+```
512+
513+You only need to enter the first of the two commands above unless you have also installed the full Xcode package. If you have only installed the command line tools, you should omit entering the *xcodebuild* command.
514+
515+#### Step 3: Download FPC
516+
517+Download the Free Pascal Compiler (FPC) and FPC source from the [Free Pascal website](https://www.freepascal.org/download.html). When you arrive at the download page, select a mirror and then choose the correct version for your operating system.
518+
519+These installation packages are built by the FPC developers and track formal releases. As these installation packages are not code signed nor notarized by Apple, you need to either control-click on the installation package and choose "Open" or right-click on the installation package and choose "Open" in the contextual menu and confirm you want to install from an Unknown Developer.
520+
521+### Other installation options
522+
523+See [[Other macOS installation options|Other FPC Installation Options]].
524+
525+## Testing the FPC Install
526+
527+You might like to try a simple and quick test of FPC at this stage. From the command line (Mac - Open an Application \> Utilities \> Terminal) start an editor (e.g. pico or nano), paste this very short program and save it as the file `helloworld.pas` (using the WriteOut command in GNU nano):
528+
529+``` pascal
530+program helloworld;
531+begin
532+ writeln('hello world !');
533+end.
534+```
535+
536+Now exit the editor and compile this simple code by typing this command, before pressing <span class="kbd">Enter</span>:
537+
538+``` bash
539+fpc helloworld.pas
540+```
541+
542+It should very quickly make an executable called, you guessed it, "helloworld". Run this executable by typing this command and then pressing <span class="kbd">Enter</span>:
543+
544+``` bash
545+./helloworld
546+```
547+
548+If that worked, well done!
549+
550+## Useful command-line switches for compiling from source
551+
552+- Significantly speed up the FPC source tree compilation
553+ - `FPMAKEOPT="-T x"` (x = the number of CPU cores you have)
554+
555+- Reduce the number of times the compiler itself gets recompiled
556+ - `NOWPOCYCLE=1`
557+
558+- Add debug information and disable optimizations during compilation of the compiler/RTL
559+ - `OPT="-gl -O-"`
560+
561+## Installing cross compilers
562+
563+A cross compiler allows you to create binaries (executables) for a platform different from the platform being used for compilation. For example, working under macOS and creating executables for Win64 or Win32 (only up to and including macOS 10.14.6 due to Apple's removal of 32 bit frameworks). For details on how to do this, see [[Cross compiling|Cross Compiling]].
564+
565+## See also
566+
567+- [[FPC|FPC Wiki Documentation]].
568+- [FPC Official Documentation](https://www.freepascal.org/docs.html).
569+- [[FPC New Features 3.2.2|FPC 3.2.2 New Features]].
570+- [[User Changes 3.2.2|FPC 3.2.2 User Changes]] - may break existing code.
571+- [[FPC New Features Trunk|FPC New Features in development version]].
572+- [[User Changes Trunk|FPC User Changes in development version]] - may break existing code.
573+
574+---
575+*From the Free Pascal wiki, page "Installing the Free Pascal Compiler", as it stood on 2024-03-04 after a change by Dbannon, 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).*
576+Category: FPC
577+Category: Install

Back to history