Sign in Join
Wiki copytemporary

Installing the Free Pascal Compiler: what changed

Revision 1 to 2. 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
35-</syntaxhighlight>
36-
3735- 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)-
3836 ``` bash
3937 apt install ./fpc-laz_3.2.2-1_amd64.deb
4038 ```
4139
4240 Note the actual name changes from time to time, use the name you downloaded !
4341
4442If 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 !
4543
4644### Downloading FPC tar balls
4745
4846Another 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.
4947
5048Here 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.
5149
5250> **Note:** A tar install **does not resolve dependencies**, if they are not already present, first install binutils, make, gcc.
5351
5452> **Note:** A tar ball install will, if you manage paths properly, allow you to have several versions of FPC installed.
5553
5654(if you want something a bit newer, please see <https://www.freepascal.org/develop.html> )
5755
5856``` bash
5957cd
6058mkdir -p bin/FPC/Tars
6159mkdir bin/FPC/SRC
6260mkdir bin/FPC/fpc-3.2.2
6361cd bin/FPC/Tars
6462# download src and compiler tars, change for different CPU (or Mac ?)
6563
6664wget https://sourceforge.net/projects/freepascal/files/Source/3.2.2/fpc-3.2.2.source.tar.gz
6765wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/fpc-3.2.2.x86_64-linux.tar
6866
6967tar xf fpc-3.2.2.x86_64-linux.tar
7068cd fpc-3.2.2.x86_64-linux
7169./install.sh
7270# when asked where to install, enter $HOME/bin/FPC/fpc-3.2.2, accept all defaults after that.
7371
7472cd ../../SRC
7573tar xzf ../Tars/fpc-3.2.2.source.tar.gz
7674
7775# Set a path to where the compiler is, add line at end of .bashrc, if you don't use bash, adjust !
7876# (! e.g. Use ~/.profile instead of ~/.bashrc so that the path is available also in Lazarus IDE.)
7977echo "PATH=\"\$HOME/bin/FPC/fpc-3.2.2/bin\":\"\$PATH\"" >> ~/.bashrc
8078source ~/.bashrc
8179
8280# trivial test
8381cd
8482fpc -iV
8583```
8684
8785> **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 -
8886>
8987> ``` bash
9088> wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/fpc-3.2.2.arm-linux.tar
9189> ```
9290>
9391> 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.
9492
9593### Downloading FPC sources from Git or zip
9694
9795If you plan to build your own compiler from source, this is the approach for you.
9896
9997The 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.
10098
10199Anyone 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.
102100
103101**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 -
104102
105103`git clone `[`https://gitlab.com/freepascal.org/fpc/source`](https://gitlab.com/freepascal.org/fpc/source)
106104
107105Once 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.
108106
109107**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):
110108
111109`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)\
112110`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)
113111
114112You would unzip the zipball and build the source as described below.
115113
116114#### Documentation sources
117115
118116The documentation sources are in a separate repository called fpcdocs, so the command to get them is:
119117
120118``` bash
121119cd ~
122120git clone https://gitlab.com/freepascal.org/fpc/documentation.git fpcdocs
123121```
124122
125123If 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.
126124
127125For more information, see the [Free Pascal website](https://www.freepascal.org/develop.html).
128126
129127### Compiling the FPC source, using preinstalled FPC
130128
131129- First install the release FPC from RPM/DEB or tarballs as described above.
132130- Get FPC sources (trunk) as described above.
133131- Make FPC sources with (execute in the source (trunk) directory):
134132
135133``` bash
136134make clean
137135make all
138136make install INSTALL_PREFIX=install/to/directory
139137```
140138
141139Decide about install/to/directory and also add options that you need.
142140
143141- 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.
144142- 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
145143
146144``` bash
147145cd install/to/directory/lib/fpc
148146mkdir etc
149147fpcmkcfg -d basepath="install/to/directory/lib/fpc/\$fpcversion" -o etc/fpc.cfg
150148```
151149
152150### Compiling the FPC source, using just downloaded FPC 3.2.2
153151
154152- Download FPC 3.2.2 (latest official release), ie tarball fpc-3.2.2.x86_64-linux.tar.
155153- Unpack this tarball to e.g. "~/Downloads/fpc", do CD to the folder containing the file "install.sh", run from Terminal:
156154
157155`$ ./install.sh`
158156
159157It 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".
160158
161159- Download the Git snapshot of FPC:
162160
163161`$ git clone `[`https://gitlab.com/freepascal.org/fpc/source`](https://gitlab.com/freepascal.org/fpc/source)
164162
165163- Do CD to new folder "source" and call:
166164
167165`$ make clean PP=/home/user/fpc-3.2.2/bin/fpc`\
168166`$ make all PP=/home/user/fpc-3.2.2/bin/fpc`
169167
170168Here 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**.
171169
172170Final compiled binary will be the file "source/compiler/ppcx64".
173171
174172## FreeBSD
175173
176174> **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]].
177175
178176### Installing from the ports collection
179177
180178The 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`.
181179
182180This must be done as root.
183181
184182``` bash
185183# cd /usr/ports/lang/fpc && make install && make clean
186184```
187185
188186If you want use development (aka trunk) version of fpc with all units included do the following:
189187
190188``` bash
191189# cd /usr/ports/lang/fpc-devel && make install clean
192190```
193191
194192Also, you can install FPC and units from pkg binaries:
195193
196194``` bash
197195# pkg install lang/fpc
198196```
199197
200198Installing development FPC and units from pkg binaries:
201199
202200``` bash
203201# pkg install lang/fpc-devel
204202```
205203
206204Once FPC is installed you can check if it's working by simply running as a normal user:
207205
208206``` bash
209207$ fpc test
210208```
211209
212210which should produce output similar to this:
213211
214212` Free Pascal Compiler version 3.2.2 [2021/08/03] for x86_64`\
215213` Copyright (c) 1993-2021 by Florian Klaempfl and others`\
216214` Target OS: FreeBSD for x86-64`\
217215` Compiling test`\
218216` Fatal: Cannot open file "test"`\
219217` Fatal: Compilation aborted`\
220218` Error: /usr/local/bin/ppcx64 returned an error exitcode`
221219
222220### Installing from tar
223221
224222Select 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).
225223
226224To install Free Pascal from a terminal:
227225
228226``` bash
229227$ fetch ftp://ftp.freepascal.org/pub/fpc/dist/3.2.2/x86_64-freebsd/fpc-3.2.2.x86_64-freebsd11.tar
230228$ tar -xf fpc-3.2.2.x86_64-freebsd11.tar
231229$ cd fpc-3.2.2.x86_64-freebsd
232230$ bash install.sh
233231```
234232
235233Replace the desired Free Pascal version (3.0.4, 3.2.0 or 3.2.2) and architecture (x86_64 or i386) as required.
236234
237235If 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.
238236
239237If 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:
240238
241239``` pascal
242240uses cthreads;
243241begin
244242 writeln('hello');
245243end.
246244```
247245
248246The executable generated for this program will cause a segmentation fault when run. To fix this issue, you need to install the GNU linker:
249247
250248``` bash
251249root# pkg install binutils
252250```
253251
254252and add a symbolic-link from `/usr/local/bin/ld.bfd` to `/bin/ld.bfd`.
255253
256254## OpenBSD
257255
258256### Installing from tar
259257
260258Select 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).
261259
262260To install Free Pascal from a terminal:
263261
264262``` bash
265263$ wget https://sourceforge.net/projects/freepascal/files/OpenBSD/3.2.2/fpc-3.2.2.x86_64-openbsd.tar
266264$ tar -xf fpc-3.2.2.x86_64-openbsd.tar
267265$ cd fpc-3.2.2.x86_64-openbsd
268266$ bash install.sh
269267```
270268
271269Replace the desired Free Pascal version (3.0.4, 3.2.0, or 3.2.2) and architecture (x86_64 or i386) as required.
272270
273271If 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.
274272
275273## Installing from source on BSD/Linux
276274
277275Effectively, you need:
278276
2792771\. 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).
280278
2812792\. 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.
282280
283281FPC build process:
284282
285283- Fetch necessary files (starting compiler), FPC source file or source svn directory
286284- If using FPC source files: extract/de-tgz in work directory,
287285- Build: enter work/fpc/ and run:
288286
289287``` bash
290288# Linux use:
291289export MAKE=`which make` ; echo $MAKE
292290# FreeBSD use (default csh, or tcsh):
293291set MAKE=`which gmake` ; echo $MAKE
294292# FreeBSD use (bash):
295293export MAKE=`which gmake` ; echo $MAKE
296294$MAKE all OPT='-gl' FPC=/path/to/startingcompiler-name-ppcx64
297295# $MAKE is make on Linux and gmake on BSD
298296# /path/to/ can be omitted when ppc386 (32 bit) or ppcx64 (64 bit) is in the path
299297```
300298
301299- Install FPC. Again in work/fpc, run
302300
303301``` bash
304302$MAKE install FPC=compiler/ppcx64 PREFIX=$THEPREFIX
305303#replace the FPC=compiler/ppcx64 (or ppc386 for 32 bit) with the relevant compiler if not on Intel x86
306304#THEPREFIX= usually is /usr/local or just /usr, but eg on NetBSD it is /usr/pkg for ports)
307305```
308306
309307- Create a symlink:
310308
311309``` bash
312310ln -s $THEPREFIX/lib/fpc/3.2.2/ppcx64 $THEPREFIX/bin/ppcx64
313311```
314312
315313- Install sources:
316314
317315``` bash
318316$MAKE install sourceinstall PREFIX=$THEPREFIX
319317```
320318
321319- Create a symlink for default FPC source path:
322320
323321``` bash
324322ln -sf $THEPREFIX/share/src/3.2.2/fpc /usr/share/fpcsrc
325323```
326324
327325- Set up fpc.cfg configuration file:
328326
329327``` bash
330328$THEPREFIX/lib/fpc/3.2.2/samplecfg $THEPREFIX/lib/fpc/3.2.0 $ETCDIR
331329```
332330
333331- 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.
334332
335333Notes:
336334
337335- 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
338336 ``` bash
339337 find . >ll
340338 ```
341339
342340- \$THEPREFIX and \$ETCDIR should be user configurable. Otherwise local installs aren't possible.
343341
344342- BSDHIER=1 on all make commands forces BSD hierarchy conventions.
345343
346344## Windows
347345
348346### Installing an FPC release with the Windows installer
349347
350348> **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.
351349
352350By 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:
353351
354352- Choose an installation location for FPC (suggested `C:\FPC\3.2.2`)
355353- Choose installation type (recommended Full Installation)
356354- Choose file associations, configuration file creation etc
357355- Install
358356- View README
359357
360358### Installing from source
361359
362360Installing 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.
363361
364362#### Obtaining the source with a command line git client
365363
366364The 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/).
367365
368366##### Source for a release version of FPC
369367
370368First 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:
371369
372370```dos
373371C:\Users\you> cd \
374372C:\> mkdir Source
375373C:\> cd Source
376374```
377375
378376Now type issue the following command at a command prompt:
379377
380378```dos
381379C:\Source> git clone -b release_3_2_2 https://gitlab.com/freepascal.org/fpc/source.git fpc-3.2.2
382380```
383381
384382Wait 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.
385383
386384##### Source for a non-release version of FPC
387385
388386There 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.
389387
390388If 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:
391389
392390*For the Fixes branch of FPC 3.2*
393391
394392```dos
395393C:\Source> git clone -b fixes_3_2 https://gitlab.com/freepascal.org/fpc/source.git fpc-fixes-3.2.0
396394```
397395
398396*For the Development (main) branch of FPC*
399397
400398```dos
401399C:\Source> git clone -b main https://gitlab.com/freepascal.org/fpc/source.git fpc-main
402400```
403401
404402Hint: To update your local copy of the repository with subsequent changes, you need only do:
405403
406404*For the Fixes branch of FPC 3.2*
407405
408406```dos
409407C:\> cd C:\Source\fpc-fixes-3.2
410408C:\Source\fpc-fixes-3.2> git clean -f -d
411409C:\Source\fpc-fixes-3.2> git pull
412410```
413411
414412*For the Development (main) branch of FPC*
415413
416414```dos
417415C:\> cd C:\Source\fpc-main
418416C:\Source\fpc-trunk> git clean -f -d
419417C:\Source\fpc-trunk> git pull
420418```
421419
422420#### Obtaining a bootstrap compiler
423421
424422To 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.
425423
426424Then restart windows.
427425
428426#### Compiling the FPC source
429427
430428**Before you start**
431429
432430- 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.
433431
434432- 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):
435433
436434` `![`fpc_windows_make.png`](/wiki-images/1/12/Fpc_windows_make.png)
437435
438436- If you need to change your path so that the correct `make.exe` is found, you can either do it temporarily or permanently.
439437 - 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:
440438
441439C:\Source\> set PATH=C:\FPC\3.2.2\bin\i386-win32;%PATH%
442440
443-</syntaxhighlight>
444-
445441- - 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.
446442
447443**Instructions**
448444
449445- At a command prompt, navigate to your local FPC source directory (eg `C:\Source\fpc-3.2.2`) by typing:
450446
451447```dos
452448C:\> cd Source\fpc-3.2.2
453449```
454450
455451- Compile the FPC source with:
456452
457453```dos
458454C:/Source/fpc-3.2.2> make distclean all
459455```
460456
461457- To overwrite an existing FPC installation in, for example, `C:\FPC`) type:
462458
463459```dos
464460C:/Source/fpc-3.2.2> make install PREFIX=C:\FPC
465461```
466462
467463- If you also need the cross-compiler to x86_64, type the following commands which will compile the cross-compiler and then install it:
468464
469465```dos
470466C:/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
471467
472468C:/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
473469```
474470
475471The cross-compiler to compile programs for Windows 64 bit may now be found here: `C:\FPC\3.2.2\bin\i386-win32\ppcrossx64`.
476472
477473Done!
478474
479475## macOS
480476
481477> **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.
482478
483479### Installing an FPC release from the official macOS packages
484480
485481#### Step 1: Download Xcode (optional)
486482
487483Xcode 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:
488484
489485- the SDKs for **iOS**, **iPadOS**, watchOS and tvOS; or
490486- to validate and upload apps to the Mac App Store; or
491487- to [[Notarization for macOS 10.14.5+|notarise]] apps for distribution outside of the Mac App Store.
492488
493489Xcode 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`.
494490
495491Older systems:
496492
497493The 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) -
498494
499495``` bash
500496mv Downloads/Xcode.app /Developer/.
501497sudo xcode-select -s /Developer/Xcode.app/Contents/Developer
502498```
503499
504500#### Step 2: Xcode Command Line Tools
505501
506502This 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)-
507503
508504``` bash
509505sudo xcode-select --install
510506sudo xcodebuild -license accept
511507```
512508
513509You 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.
514510
515511#### Step 3: Download FPC
516512
517513Download 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.
518514
519515These 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.
520516
521517### Other installation options
522518
523519See [[Other macOS installation options|Other FPC Installation Options]].
524520
525521## Testing the FPC Install
526522
527523You 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):
528524
529525``` pascal
530526program helloworld;
531527begin
532528 writeln('hello world !');
533529end.
534530```
535531
536-Now exit the editor and compile this simple code by typing this command, before pressing <span class="kbd">Enter</span>:
532+Now exit the editor and compile this simple code by typing this command, before pressing `Enter`:
537533
538534``` bash
539535fpc helloworld.pas
540536```
541537
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>:
538+It should very quickly make an executable called, you guessed it, "helloworld". Run this executable by typing this command and then pressing `Enter`:
543539
544540``` bash
545541./helloworld
546542```
547543
548544If that worked, well done!
549545
550546## Useful command-line switches for compiling from source
551547
552548- Significantly speed up the FPC source tree compilation
553549 - `FPMAKEOPT="-T x"` (x = the number of CPU cores you have)
554550
555551- Reduce the number of times the compiler itself gets recompiled
556552 - `NOWPOCYCLE=1`
557553
558554- Add debug information and disable optimizations during compilation of the compiler/RTL
559555 - `OPT="-gl -O-"`
560556
561557## Installing cross compilers
562558
563559A 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]].
564560
565561## See also
566562
567563- [[FPC|FPC Wiki Documentation]].
568564- [FPC Official Documentation](https://www.freepascal.org/docs.html).
569565- [[FPC New Features 3.2.2|FPC 3.2.2 New Features]].
570566- [[User Changes 3.2.2|FPC 3.2.2 User Changes]] - may break existing code.
571567- [[FPC New Features Trunk|FPC New Features in development version]].
572568- [[User Changes Trunk|FPC User Changes in development version]] - may break existing code.
573569
574570---
575571*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).*
576572Category: FPC
577573Category: Install

Back to history