Sign in Join
Wiki copytemporary

Installing the Free Pascal Compiler: what changed

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

OldNewLine
11While 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:
22
33- Intellectual curiosity - you want to discover the compiler's speed, using a medium sized application like the compiler itself.
44- 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.
55- 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.
66- Do it yourself - you prefer to build applications from source where possible.
77- 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.
88
99And the most obvious reason of all:
1010
1111- New Version - you are creating a new release of the compiler.
1212
1313This document will try to help you do these things.
1414
1515## Overview
1616
1717There 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.
1818
1919It 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.
2020
2121There 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.
2222
2323## Linux
2424
2525### Downloading FPC binary packages
2626
2727> **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.
2828
2929With 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 -
3030
3131- 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 -
3232
3333// or perhaps rpm -Uvh fpc-3.2.2-1.x86_64.rpm
3434
3535- 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)-
3636 ``` bash
3737 apt install ./fpc-laz_3.2.2-1_amd64.deb
3838 ```
3939
4040 Note the actual name changes from time to time, use the name you downloaded !
4141
4242If 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 !
4343
4444### Downloading FPC tar balls
4545
4646Another 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.
4747
4848Here 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.
4949
5050> **Note:** A tar install **does not resolve dependencies**, if they are not already present, first install binutils, make, gcc.
5151
5252> **Note:** A tar ball install will, if you manage paths properly, allow you to have several versions of FPC installed.
5353
5454(if you want something a bit newer, please see <https://www.freepascal.org/develop.html> )
5555
5656``` bash
5757cd
5858mkdir -p bin/FPC/Tars
5959mkdir bin/FPC/SRC
6060mkdir bin/FPC/fpc-3.2.2
6161cd bin/FPC/Tars
6262# download src and compiler tars, change for different CPU (or Mac ?)
6363
6464wget https://sourceforge.net/projects/freepascal/files/Source/3.2.2/fpc-3.2.2.source.tar.gz
6565wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/fpc-3.2.2.x86_64-linux.tar
6666
6767tar xf fpc-3.2.2.x86_64-linux.tar
6868cd fpc-3.2.2.x86_64-linux
6969./install.sh
7070# when asked where to install, enter $HOME/bin/FPC/fpc-3.2.2, accept all defaults after that.
7171
7272cd ../../SRC
7373tar xzf ../Tars/fpc-3.2.2.source.tar.gz
7474
7575# Set a path to where the compiler is, add line at end of .bashrc, if you don't use bash, adjust !
7676# (! e.g. Use ~/.profile instead of ~/.bashrc so that the path is available also in Lazarus IDE.)
7777echo "PATH=\"\$HOME/bin/FPC/fpc-3.2.2/bin\":\"\$PATH\"" >> ~/.bashrc
7878source ~/.bashrc
7979
8080# trivial test
8181cd
8282fpc -iV
8383```
8484
8585> **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 -
8686>
8787> ``` bash
8888> wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/fpc-3.2.2.arm-linux.tar
8989> ```
9090>
9191> 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.
9292
9393### Downloading FPC sources from Git or zip
9494
9595If you plan to build your own compiler from source, this is the approach for you.
9696
9797The 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.
9898
9999Anyone 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.
100100
101101**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 -
102102
103-`git clone `[`https://gitlab.com/freepascal.org/fpc/source`](https://gitlab.com/freepascal.org/fpc/source)
103+```text
104+git clone https://gitlab.com/freepascal.org/fpc/source
105+```
104106
105107Once 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.
106108
107109**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):
108110
109-`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)\
110-`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)
111+```text
112+wget https://gitlab.com/freepascal.org/fpc/source/-/archive/fixes_3_2/source-fixes_3_2.zip
113+wget https://gitlab.com/freepascal.org/fpc/source/-/archive/release_3_2_2/source-release_3_2_2.zip
114+```
111115
112116You would unzip the zipball and build the source as described below.
113117
114118#### Documentation sources
115119
116120The documentation sources are in a separate repository called fpcdocs, so the command to get them is:
117121
118122``` bash
119123cd ~
120124git clone https://gitlab.com/freepascal.org/fpc/documentation.git fpcdocs
121125```
122126
123127If 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.
124128
125129For more information, see the [Free Pascal website](https://www.freepascal.org/develop.html).
126130
127131### Compiling the FPC source, using preinstalled FPC
128132
129133- First install the release FPC from RPM/DEB or tarballs as described above.
130134- Get FPC sources (trunk) as described above.
131135- Make FPC sources with (execute in the source (trunk) directory):
132136
133137``` bash
134138make clean
135139make all
136140make install INSTALL_PREFIX=install/to/directory
137141```
138142
139143Decide about install/to/directory and also add options that you need.
140144
141145- 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.
142146- 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
143147
144148``` bash
145149cd install/to/directory/lib/fpc
146150mkdir etc
147151fpcmkcfg -d basepath="install/to/directory/lib/fpc/\$fpcversion" -o etc/fpc.cfg
148152```
149153
150154### Compiling the FPC source, using just downloaded FPC 3.2.2
151155
152156- Download FPC 3.2.2 (latest official release), ie tarball fpc-3.2.2.x86_64-linux.tar.
153157- Unpack this tarball to e.g. "~/Downloads/fpc", do CD to the folder containing the file "install.sh", run from Terminal:
154158
155-`$ ./install.sh`
159+```text
160+$ ./install.sh
161+```
156162
157163It 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".
158164
159165- Download the Git snapshot of FPC:
160166
161-`$ git clone `[`https://gitlab.com/freepascal.org/fpc/source`](https://gitlab.com/freepascal.org/fpc/source)
167+```text
168+$ git clone https://gitlab.com/freepascal.org/fpc/source
169+```
162170
163171- Do CD to new folder "source" and call:
164172
165-`$ make clean PP=/home/user/fpc-3.2.2/bin/fpc`\
166-`$ make all PP=/home/user/fpc-3.2.2/bin/fpc`
173+```text
174+$ make clean PP=/home/user/fpc-3.2.2/bin/fpc
175+$ make all PP=/home/user/fpc-3.2.2/bin/fpc
176+```
167177
168178Here 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**.
169179
170180Final compiled binary will be the file "source/compiler/ppcx64".
171181
172182## FreeBSD
173183
174184> **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]].
175185
176186### Installing from the ports collection
177187
178188The 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`.
179189
180190This must be done as root.
181191
182192``` bash
183193# cd /usr/ports/lang/fpc && make install && make clean
184194```
185195
186196If you want use development (aka trunk) version of fpc with all units included do the following:
187197
188198``` bash
189199# cd /usr/ports/lang/fpc-devel && make install clean
190200```
191201
192202Also, you can install FPC and units from pkg binaries:
193203
194204``` bash
195205# pkg install lang/fpc
196206```
197207
198208Installing development FPC and units from pkg binaries:
199209
200210``` bash
201211# pkg install lang/fpc-devel
202212```
203213
204214Once FPC is installed you can check if it's working by simply running as a normal user:
205215
206216``` bash
207217$ fpc test
208218```
209219
210220which should produce output similar to this:
211221
212-` Free Pascal Compiler version 3.2.2 [2021/08/03] for x86_64`\
213-` Copyright (c) 1993-2021 by Florian Klaempfl and others`\
214-` Target OS: FreeBSD for x86-64`\
215-` Compiling test`\
216-` Fatal: Cannot open file "test"`\
217-` Fatal: Compilation aborted`\
218-` Error: /usr/local/bin/ppcx64 returned an error exitcode`
222+```text
223+ Free Pascal Compiler version 3.2.2 [2021/08/03] for x86_64
224+ Copyright (c) 1993-2021 by Florian Klaempfl and others
225+ Target OS: FreeBSD for x86-64
226+ Compiling test
227+ Fatal: Cannot open file "test"
228+ Fatal: Compilation aborted
229+ Error: /usr/local/bin/ppcx64 returned an error exitcode
230+```
219231
220232### Installing from tar
221233
222234Select 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).
223235
224236To install Free Pascal from a terminal:
225237
226238``` bash
227239$ fetch ftp://ftp.freepascal.org/pub/fpc/dist/3.2.2/x86_64-freebsd/fpc-3.2.2.x86_64-freebsd11.tar
228240$ tar -xf fpc-3.2.2.x86_64-freebsd11.tar
229241$ cd fpc-3.2.2.x86_64-freebsd
230242$ bash install.sh
231243```
232244
233245Replace the desired Free Pascal version (3.0.4, 3.2.0 or 3.2.2) and architecture (x86_64 or i386) as required.
234246
235247If 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.
236248
237249If 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:
238250
239251``` pascal
240252uses cthreads;
241253begin
242254 writeln('hello');
243255end.
244256```
245257
246258The executable generated for this program will cause a segmentation fault when run. To fix this issue, you need to install the GNU linker:
247259
248260``` bash
249261root# pkg install binutils
250262```
251263
252264and add a symbolic-link from `/usr/local/bin/ld.bfd` to `/bin/ld.bfd`.
253265
254266## OpenBSD
255267
256268### Installing from tar
257269
258270Select 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).
259271
260272To install Free Pascal from a terminal:
261273
262274``` bash
263275$ wget https://sourceforge.net/projects/freepascal/files/OpenBSD/3.2.2/fpc-3.2.2.x86_64-openbsd.tar
264276$ tar -xf fpc-3.2.2.x86_64-openbsd.tar
265277$ cd fpc-3.2.2.x86_64-openbsd
266278$ bash install.sh
267279```
268280
269281Replace the desired Free Pascal version (3.0.4, 3.2.0, or 3.2.2) and architecture (x86_64 or i386) as required.
270282
271283If 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.
272284
273285## Installing from source on BSD/Linux
274286
275287Effectively, you need:
276288
2772891\. 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).
278290
2792912\. 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.
280292
281293FPC build process:
282294
283295- Fetch necessary files (starting compiler), FPC source file or source svn directory
284296- If using FPC source files: extract/de-tgz in work directory,
285297- Build: enter work/fpc/ and run:
286298
287299``` bash
288300# Linux use:
289301export MAKE=`which make` ; echo $MAKE
290302# FreeBSD use (default csh, or tcsh):
291303set MAKE=`which gmake` ; echo $MAKE
292304# FreeBSD use (bash):
293305export MAKE=`which gmake` ; echo $MAKE
294306$MAKE all OPT='-gl' FPC=/path/to/startingcompiler-name-ppcx64
295307# $MAKE is make on Linux and gmake on BSD
296308# /path/to/ can be omitted when ppc386 (32 bit) or ppcx64 (64 bit) is in the path
297309```
298310
299311- Install FPC. Again in work/fpc, run
300312
301313``` bash
302314$MAKE install FPC=compiler/ppcx64 PREFIX=$THEPREFIX
303315#replace the FPC=compiler/ppcx64 (or ppc386 for 32 bit) with the relevant compiler if not on Intel x86
304316#THEPREFIX= usually is /usr/local or just /usr, but eg on NetBSD it is /usr/pkg for ports)
305317```
306318
307319- Create a symlink:
308320
309321``` bash
310322ln -s $THEPREFIX/lib/fpc/3.2.2/ppcx64 $THEPREFIX/bin/ppcx64
311323```
312324
313325- Install sources:
314326
315327``` bash
316328$MAKE install sourceinstall PREFIX=$THEPREFIX
317329```
318330
319331- Create a symlink for default FPC source path:
320332
321333``` bash
322334ln -sf $THEPREFIX/share/src/3.2.2/fpc /usr/share/fpcsrc
323335```
324336
325337- Set up fpc.cfg configuration file:
326338
327339``` bash
328340$THEPREFIX/lib/fpc/3.2.2/samplecfg $THEPREFIX/lib/fpc/3.2.0 $ETCDIR
329341```
330342
331343- 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.
332344
333345Notes:
334346
335347- 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
336348 ``` bash
337349 find . >ll
338350 ```
339351
340352- \$THEPREFIX and \$ETCDIR should be user configurable. Otherwise local installs aren't possible.
341353
342354- BSDHIER=1 on all make commands forces BSD hierarchy conventions.
343355
344356## Windows
345357
346358### Installing an FPC release with the Windows installer
347359
348360> **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.
349361
350362By 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:
351363
352364- Choose an installation location for FPC (suggested `C:\FPC\3.2.2`)
353365- Choose installation type (recommended Full Installation)
354366- Choose file associations, configuration file creation etc
355367- Install
356368- View README
357369
358370### Installing from source
359371
360372Installing 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.
361373
362374#### Obtaining the source with a command line git client
363375
364376The 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/).
365377
366378##### Source for a release version of FPC
367379
368380First 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:
369381
370382```dos
371383C:\Users\you> cd \
372384C:\> mkdir Source
373385C:\> cd Source
374386```
375387
376388Now type issue the following command at a command prompt:
377389
378390```dos
379391C:\Source> git clone -b release_3_2_2 https://gitlab.com/freepascal.org/fpc/source.git fpc-3.2.2
380392```
381393
382394Wait 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.
383395
384396##### Source for a non-release version of FPC
385397
386398There 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.
387399
388400If 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:
389401
390402*For the Fixes branch of FPC 3.2*
391403
392404```dos
393405C:\Source> git clone -b fixes_3_2 https://gitlab.com/freepascal.org/fpc/source.git fpc-fixes-3.2.0
394406```
395407
396408*For the Development (main) branch of FPC*
397409
398410```dos
399411C:\Source> git clone -b main https://gitlab.com/freepascal.org/fpc/source.git fpc-main
400412```
401413
402414Hint: To update your local copy of the repository with subsequent changes, you need only do:
403415
404416*For the Fixes branch of FPC 3.2*
405417
406418```dos
407419C:\> cd C:\Source\fpc-fixes-3.2
408420C:\Source\fpc-fixes-3.2> git clean -f -d
409421C:\Source\fpc-fixes-3.2> git pull
410422```
411423
412424*For the Development (main) branch of FPC*
413425
414426```dos
415427C:\> cd C:\Source\fpc-main
416428C:\Source\fpc-trunk> git clean -f -d
417429C:\Source\fpc-trunk> git pull
418430```
419431
420432#### Obtaining a bootstrap compiler
421433
422434To 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.
423435
424436Then restart windows.
425437
426438#### Compiling the FPC source
427439
428440**Before you start**
429441
430442- 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.
431443
432444- 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):
433445
434-` `![`fpc_windows_make.png`](/wiki-images/1/12/Fpc_windows_make.png)
446+```text
447+ file:fpc_windows_make.png
448+```
435449
436450- If you need to change your path so that the correct `make.exe` is found, you can either do it temporarily or permanently.
437451 - 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:
438452
439453C:\Source\> set PATH=C:\FPC\3.2.2\bin\i386-win32;%PATH%
440454
441455- - 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.
442456
443457**Instructions**
444458
445459- At a command prompt, navigate to your local FPC source directory (eg `C:\Source\fpc-3.2.2`) by typing:
446460
447461```dos
448462C:\> cd Source\fpc-3.2.2
449463```
450464
451465- Compile the FPC source with:
452466
453467```dos
454468C:/Source/fpc-3.2.2> make distclean all
455469```
456470
457471- To overwrite an existing FPC installation in, for example, `C:\FPC`) type:
458472
459473```dos
460474C:/Source/fpc-3.2.2> make install PREFIX=C:\FPC
461475```
462476
463477- If you also need the cross-compiler to x86_64, type the following commands which will compile the cross-compiler and then install it:
464478
465479```dos
466480C:/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
467481
468482C:/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
469483```
470484
471485The cross-compiler to compile programs for Windows 64 bit may now be found here: `C:\FPC\3.2.2\bin\i386-win32\ppcrossx64`.
472486
473487Done!
474488
475489## macOS
476490
477491> **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.
478492
479493### Installing an FPC release from the official macOS packages
480494
481495#### Step 1: Download Xcode (optional)
482496
483497Xcode 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:
484498
485499- the SDKs for **iOS**, **iPadOS**, watchOS and tvOS; or
486500- to validate and upload apps to the Mac App Store; or
487501- to [[Notarization for macOS 10.14.5+|notarise]] apps for distribution outside of the Mac App Store.
488502
489503Xcode 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`.
490504
491505Older systems:
492506
493507The 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) -
494508
495509``` bash
496510mv Downloads/Xcode.app /Developer/.
497511sudo xcode-select -s /Developer/Xcode.app/Contents/Developer
498512```
499513
500514#### Step 2: Xcode Command Line Tools
501515
502516This 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)-
503517
504518``` bash
505519sudo xcode-select --install
506520sudo xcodebuild -license accept
507521```
508522
509523You 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.
510524
511525#### Step 3: Download FPC
512526
513527Download 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.
514528
515529These 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.
516530
517531### Other installation options
518532
519533See [[Other macOS installation options|Other FPC Installation Options]].
520534
521535## Testing the FPC Install
522536
523537You 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):
524538
525539``` pascal
526540program helloworld;
527541begin
528542 writeln('hello world !');
529543end.
530544```
531545
532546Now exit the editor and compile this simple code by typing this command, before pressing `Enter`:
533547
534548``` bash
535549fpc helloworld.pas
536550```
537551
538552It should very quickly make an executable called, you guessed it, "helloworld". Run this executable by typing this command and then pressing `Enter`:
539553
540554``` bash
541555./helloworld
542556```
543557
544558If that worked, well done!
545559
546560## Useful command-line switches for compiling from source
547561
548562- Significantly speed up the FPC source tree compilation
549563 - `FPMAKEOPT="-T x"` (x = the number of CPU cores you have)
550564
551565- Reduce the number of times the compiler itself gets recompiled
552566 - `NOWPOCYCLE=1`
553567
554568- Add debug information and disable optimizations during compilation of the compiler/RTL
555569 - `OPT="-gl -O-"`
556570
557571## Installing cross compilers
558572
559573A 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]].
560574
561575## See also
562576
563577- [[FPC|FPC Wiki Documentation]].
564578- [FPC Official Documentation](https://www.freepascal.org/docs.html).
565579- [[FPC New Features 3.2.2|FPC 3.2.2 New Features]].
566580- [[User Changes 3.2.2|FPC 3.2.2 User Changes]] - may break existing code.
567581- [[FPC New Features Trunk|FPC New Features in development version]].
568582- [[User Changes Trunk|FPC User Changes in development version]] - may break existing code.
569583
570584---
571585*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).*
572586Category: FPC
573587Category: Install

Back to history