Difference between revisions of "Installing the Free Pascal Compiler"

From Free Pascal wiki
m (Installing an FPC release with the Windows installer: Remove WIP warning)
m (Step 2: Xcode Command Line Tools: cannot > does not)
 
(41 intermediate revisions by 5 users not shown)
Line 3: Line 3:
 
== Overview ==
 
== Overview ==
  
There are a number of ways to install FPC on your system. The current version and trunk and, sometimes beta and release candidates are available direct from the FPC website https://sourceforge.net/projects/freepascal/files/ (tar, exe, rpm, dmg 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 distro's repositories but may find it is out dated.  
+
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 [https://sourceforge.net/projects/freepascal/files/ FPC website] (tar, exe, rpm, dmg, pkg files).  In addition, versions of FPC are provided (including rpm and deb files) from the [http://sourceforge.net/projects/lazarus/files/ Lazarus download site].  Linux users can almost certainly find FPC in their distribution's repositories but may find that it is outdated.  
  
It is possible to build FPC from source, typically each release can 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.
+
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.
  
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 is very comprehensive.
+
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.
  
 
== Linux ==
 
== Linux ==
  
 
=== FPC Binary Packages ===
 
=== FPC Binary Packages ===
 +
 +
{{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. }}
  
 
With the recent release of FPC 3.2.0, only a few distributions will have the new FPC compiler in its repositories.  You can do one of -
 
With the recent release of FPC 3.2.0, only a few distributions will have the new FPC compiler in its repositories.  You can do one of -
Line 21: Line 23:
  
 
=== FPC Tar Balls ===
 
=== FPC Tar Balls ===
 +
 
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.
 
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.
  
Line 44: Line 47:
 
tar xzf ../Tars/fpc-3.2.0.source.tar.gz
 
tar xzf ../Tars/fpc-3.2.0.source.tar.gz
  
# Set a path to where the compiler is, add line at end of .bashrc, if you don't use bash, adjust !  
+
# Set a path to where the compiler is, add line at end of .bashrc, if you don't use bash, adjust !
 +
# (! e.g. Use ~/.profile instead of ~/.bashrc so that the path is available also in Lazarus IDE.)
 
echo "PATH=\"\$HOME/bin/FPC/fpc-3.2.0/bin\":\"\$PATH\"" >> ~/.bashrc
 
echo "PATH=\"\$HOME/bin/FPC/fpc-3.2.0/bin\":\"\$PATH\"" >> ~/.bashrc
 
source ~/.bashrc
 
source ~/.bashrc
Line 140: Line 144:
  
 
For more information, see the [https://www.freepascal.org/develop.html Free Pascal website].
 
For more information, see the [https://www.freepascal.org/develop.html Free Pascal website].
 +
 +
=== Compiling the FPC source ===
 +
 +
* First install the release FPC from rpm/deb or tar balls as described above.
 +
* Get FPC sources (trunk) as described above.
 +
* Make FPC sources with (execute in the source (trunk) directory)
 +
<syntaxhighlight lang="bash">
 +
make clean all
 +
make install INSTALL_PREFIX=install/to/directory
 +
</syntaxhighlight>
 +
Decide about install/to/directory and also add options that you need.
 +
* 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.
 +
* 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
 +
<syntaxhighlight lang="bash">
 +
cd install/to/directory/lib/fpc
 +
mkdir etc
 +
fpcmkcfg -d basepath="install/to/directory/lib/fpc/\$fpcversion" -o etc/fpc.cfg
 +
</syntaxhighlight>
  
 
== FreeBSD ==
 
== FreeBSD ==
Line 299: Line 321:
 
=== Installing an FPC release with the Windows installer ===
 
=== Installing an FPC release with the Windows installer ===
 
   
 
   
 +
{{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.}}
 +
 
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 [https://sourceforge.net/projects/freepascal/files/Win32/3.2.0/ SourceForge repository for FPC 3.2.0] - this release contains the current 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:
 
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 [https://sourceforge.net/projects/freepascal/files/Win32/3.2.0/ SourceForge repository for FPC 3.2.0] - this release contains the current 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:
  
* Choose an installatio9n location for FPC (suggested <tt>C:\FPC\3.2.0</tt>)
+
* Choose an installation location for FPC (suggested <tt>C:\FPC\3.2.0</tt>)
 
* Choose installation type (recommended Full Installation)
 
* Choose installation type (recommended Full Installation)
 
* Choose file associations, configuration file creation etc
 
* Choose file associations, configuration file creation etc
Line 337: Line 361:
 
There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2.0 branch which includes additional fixes to the released 3.2.0 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.
 
There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2.0 branch which includes additional fixes to the released 3.2.0 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.
  
If it does not already exist, create a directory in which you'd like to keep the source. Any normal user can do this. Create a directory for FPC (eg <tt>C:\Source</tt>), then issue the following command at a command prompt:
+
If it does not already exist, create a directory in which you'd like to keep the FPC source (eg <tt>C:\Source</tt>). Any normal user can do this. Now type the following command at a command prompt:
  
 
''For the Fixes branch of FPC 3.2.0''
 
''For the Fixes branch of FPC 3.2.0''
  
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
C:/Source> svn checkout https://svn.freepascal.org/svn/fpc/tags/release_3_2_0 fpc-3.2.0
+
C:\Source> svn checkout https://svn.freepascal.org/svn/fpc/branches/fixes_3_2_0 fpc-fixes-3.2.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 351: Line 375:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Hint: To download/update your copy of the repository with subsequent changes, you need only do:
+
Hint: To update your local copy of the repository with subsequent changes, you need only do:
  
 
''For the Fixes branch of FPC 3.2.0''
 
''For the Fixes branch of FPC 3.2.0''
  
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
C:\> cd Source\fpc-fixes-3.2.0
+
C:\> cd C:\Source\fpc-fixes-3.2.0
 +
C:\Source\fpc-fixes-3.2.0> svn clean --remove-unversioned --remove-ignored
 
C:\Source\fpc-fixes-3.2.0> svn update
 
C:\Source\fpc-fixes-3.2.0> svn update
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 363: Line 388:
  
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
C:\> cd Source\fpc-trunk
+
C:\> cd C:\Source\fpc-trunk
 +
C:\Source\fpc-trunk> svn clean --remove-unversioned --remove-ignored
 
C:\Source\fpc-trunk> svn update
 
C:\Source\fpc-trunk> svn update
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
==== Obtaining the source with the GUI TortoiseSVN client ====
 
==== Obtaining the source with the GUI TortoiseSVN client ====
 +
 +
The first thing you will probably need to do is download the GUI TortoiseSVN Subversion client from TortoiseSVN website [https://tortoisesvn.net/downloads.html Download file area] if you do not already have it available.
 +
 +
After downloading the appropriate Windows installer and installing it, you are ready to begin. You will notice that TortoiseSVN has added a number of shortcuts to the File Explorer context menu so that you can work easily with svn without needing to use the command prompt.
  
 
===== Source for a release version of FPC =====
 
===== Source for a release version of FPC =====
  
t/c
+
To download the latest release version Free Pascal Compiler source from the Subversion repository, first create the directory in which you'd like to keep the source. Any normal user can do this:
 +
 
 +
* Open File Explorer and navigate to "Local Disk C:"
 +
* Choose Home > New folder in File Explorer and create a directory for the FPC source (eg <tt>C:\Source</tt>).
 +
* Right click in File Explorer in your newly created directory and you should see an entry for "SVN Checkout..." in the context menu, choose this entry and you will be presented with a TortoiseSVN Checkout Dialog.
 +
* Fill in the "URL of the Repository" field with this URL: https://svn.freepascal.org/svn/fpc/tags/release_3_2_0
 +
* In the "Checkout directory" field add <tt>fpc-3.2.0</tt> to the existing C:\Source\</tt> in the field so you end up with <tt>C:\Source\fpc-3.2.0</tt>. This is the directory which will house your local copy of the source repository.
 +
* Leave the other fields at their default and click OK.
 +
* Now you will be presented with a new dialog which shows the progress of the checkout... wait while the Subversion repository is downloaded to the fpc-3.2.0 directory in your newly created Source directory. This can take a while... have a look at the helpful [https://forum.lazarus.freepascal.org/ Free Pascal Forums] 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.
  
 
===== Source for a non-release version of FPC =====
 
===== Source for a non-release version of FPC =====
  
After installing the [http://tortoisesvn.tigris.org/ TortoiseSVN] Subversion client, download the sources from the svn repository using a URL for each directory (!?really?!):
+
There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2.0 branch which includes additional fixes to the released 3.2.0 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.
  
  Dir: c:\freepascal\binutils\i386-win32\
+
The instructions are the same as for a [[#Source for a non-release version of FPC|release version]] of the Free Pascal Compiler given above, except that you will need to replace the "URL of the Repository" and "Checkout directory" fields with the appropriate values set out below:
  URL: https://svn.freepascal.org/svn/fpcbuild/branches/fixes_3_0/install/binw32
 
  
or for fpc trunk:
+
''For the Fixes branch of FPC''
  
   Dir: c:\freepascal\binutils\i386-win32\
+
   Repository URL: <nowiki>https://svn.freepascal.org/svn/fpc/branches/fixes_3_2_0</nowiki>
  URL: https://svn.freepascal.org/svn/fpcbuild/trunk/install/binw32
+
  Checkout Directory: C:\Source\fpc-fixes-3.2.0
  
  Dir: c:\freepascal\fpc\3.0.4
+
''For the Development (trunk) branch of FPC''
   URL: https://svn.freepascal.org/svn/fpc/branches/fixes_3_0/
+
 
 +
   Repository URL: <nowiki>https://svn.freepascal.org/svn/fpc/trunk </nowiki>
 +
  Checkout Directory: C:\Source\fpc-trunk
 +
 
 +
''Updating your local repository''
  
or for fpc trunk:
+
To '''update''' your local copy of the repository with subsequent source changes:
  
  Dir: c:\freepascal\fpc\trunk
+
* Open File Explorer, navigate to your <tt>C:\Source</tt> and right-click on the <tt>fpc-fixes-3.2.0</tt> or <tt>fpc-trunk</tt> directory.
  URL: https://svn.freepascal.org/svn/fpc/trunk/
+
* You should see an entry for "TortoiseSVN", if you hover over it, another longer context menu will be presented from which you should choose "Clean up...". In the Cleanup dialog, check both "Delete unversioned files and folders" and "Delete ignored files and folders".
 +
* Now right-click on the <tt>fpc-fixes-3.2.0</tt> or <tt>fpc-trunk</tt> directory again and you should see an entry for "SVN Update" in the context menu, choose this entry and you will be presented with a TortoiseSVN Update Dialog and the update will start without you needing to do anything else. When the update finishes, click OK to exit.
  
 
==== Obtaining a bootstrap compiler ====
 
==== Obtaining a bootstrap compiler ====
Line 401: Line 443:
 
==== Compiling the FPC source ====
 
==== Compiling the FPC source ====
  
Hints:
+
'''Before you start''' 
 +
 
 +
* 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 <tt>C:\FPC</tt> and the FPC 3.2.0 release files are placed in <tt>C:\FPC\3.2.0</tt>. 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 (<tt>C:\FPC</tt>) but you must also make sure that the <tt>C:\FPC\bin\i386-win32\</tt> directory is added to your path environment variable.
 +
 
 +
* Check that the <tt>make.exe</tt> 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 <tt>make -v</tt>. The result should be (or very similar):
 +
 
 +
  [[file:fpc_windows_make.png]]
  
* Windows (7+) requires that an elevated user status command prompt be used. From the start menu for "Command Prompt" right click and select "Run as Administrator".
+
* If you need to change your path so that the correct <tt>make.exe</tt> is found, you can either do it temporarily or permanently.
* YOUR-PREFIX is totally dependent on where you installed FPC to. At the time of this writing, the binaries are instructed to use a default location of "C:\FPC" and they were placed in "C:\FPC\3.2.0".  Under Linux, the make install scripts were adjusted to create a new sub-folder IF the FPC version changed since last build. The Windows scripts do not. So if you know the sub-folder name ie. 3.1.1 you can specify that. However, since versions change frequently, it is recommended that you just select and maintain a single PREFIX with no respect for FPC versions. A good prefix is C:\FPC but you must also make sure that the C:\FPC\bin\i386-win32\ folder is added to your path environment variable (see above on how to set your path and change it from the binary version to the newly compiled one).
+
** To change it temporarily (it is in effect only until you close the current command prompt) to find <tt>make.exe</tt> in <tt>C:\FPC\3.2.0\bin\i386-win32</tt>, at a command prompt type: <syntaxhighlight lang=dos>
 +
C:\Source> set PATH=C:\FPC\3.2.0\bin\i386-win32;%PATH%
 +
</syntaxhighlight>
 +
** 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 <tt>C:\FPC\3.2.0\bin\i386-win32</tt> occurs first.
  
Instructions:
+
'''Instructions'''
  
 
* At a command prompt, navigate to your local FPC source directory (eg <tt>C:\Source\fpc-3.2.0</tt>) by typing:
 
* At a command prompt, navigate to your local FPC source directory (eg <tt>C:\Source\fpc-3.2.0</tt>) by typing:
Line 417: Line 468:
  
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
C:/Source/fpc-3.2.0> make all
+
C:/Source/fpc-3.2.0> make distclean all
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* To overwrite an existing FPC installation in YOUR-PREFIX (eg <tt>C:\FPC</tt>) type:  
+
* To overwrite an existing FPC installation in, for example, <tt>C:\FPC</tt>) type:  
  
 
<syntaxhighlight lang=dos>
 
<syntaxhighlight lang=dos>
C:/Source/fpc-3.2.0> make install PREFIX=YOUR-PREFIX
+
C:/Source/fpc-3.2.0> make install PREFIX=C:\FPC
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
* If you also need the cross-compiler to x86_64, type the following commands which will compile the cross-compiler and then install it:
  
Version FPC '''3.2.0''' or '''trunk'''
+
<syntaxhighlight lang="dos">
 +
C:/Source/fpc-3.2.0> make all OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=C:\FPC\3.2.0 PP=C:\FPC\3.2.0\bin\i386-win32\ppc386.exe DATA2INC=C:\FPC\3.2.0\bin\i386-win32\data2inc.exe
  
''STEP #1: Create directories and get the sources''
+
C:/Source/fpc-3.2.0> make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=C:\FPC\3.2.0 PP=C:\FPC\3.2.0\bin\i386-win32\ppc386.exe DATA2INC=C:\FPC\3.2.0\bin\i386\win32\data2inc.exe
 +
</syntaxhighlight>
  
Create the following directories:
+
The cross-compiler to compile programs for Windows 64 bit may now be found here: <tt>C:\FPC\3.2.0\bin\i386-win32\ppcrossx64</tt>.
  c:\freepascal\
 
  c:\freepascal\binutils\
 
  c:\freepascal\binutils\i386-win32\
 
  c:\freepascal\fpc\
 
  c:\freepascal\fpc\3.2.0\
 
  
or for fpc trunk:
+
Done!
  c:\freepascal\
 
  c:\freepascal\binutils\
 
  c:\freepascal\binutils\i386-win32\
 
  c:\freepascal\fpc\
 
  c:\freepascal\fpc\trunk\
 
  
You will need the latest '''released''' compiler to build a new compiler. Get the ppc386 (the compiler) with FTP (below) and unzip it in c:\freepascal\binutils\
+
== macOS ==
  
  ftp://ftp.freepascal.org/pub/fpc/dist/3.2.0/bootstrap/i386-win32-ppc386.zip
+
{{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.}}
  
''STEP #2: Create a BAT file to compile FPC''
+
{{Note| For installation on Apple Silicon/AArch64, please refer to [[macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FApple_Silicon_Support|Apple Silicon Support]] for build instructions for a native Free Pascal Compiler.}}
  
After everything is downloaded, we need a BAT file to compile the FPC sources.
+
=== Installing an FPC release from the official macOS packages ===
Create a new file c:\freepascal\makefpc.bat and copy/paste the following script:
 
  
<syntaxhighlight lang="dos">
+
==== Step 1: Download Xcode (optional) ====
@echo on
+
 
set myroot=c:\freepascal
+
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:
set myFPC=%myroot%\fpc\3.2.0
+
 
set mybinutils=%myroot%\binutils
+
* the SDKs for '''iOS''', '''iPadOS''', watchOS and tvOS; or
set PATH=%PATH%;%mybinutils%\i386-win32;%myFPC%\bin\i386-win32
+
* to validate and upload apps to the Mac App Store; or
cd %myFPC%
+
* to [[Notarization for macOS 10.14.5+|notarise]] apps for distribution outside of the Mac App Store.
rd /s /q %myfpc%\examples
+
 
svn cleanup . --remove-unversioned  --remove-ignored
+
Xcode 11.3.1 for use on macOS 10.14 Mojave must now be installed by downloading it from [http://developer.apple.com/ Apple Developer Connection] (ADC), which requires free registration. Xcode 11.4.x for use on macOS 10.15 Catalina can be installed from the [https://apps.apple.com/us/genre/mac-developer-tools/id12002?mt=12 Mac App store]. 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 <tt>xcode-select</tt>.
make distclean all install INSTALL_PREFIX=%myFPC% PP=%mybinutils%\ppc386.exe DATA2INC=%myFPC%\utils\data2inc.exe
+
 
cd /d %myFPC%\bin\i386-win32
+
Older systems:
fpcmkcfg -d basepath=%myFPC% -o .\fpc.cfg
+
 
copy fpc.exe %mybinutils%\i386-win32
+
The developer tools can be installed from the original macOS installation disks or a newer copy downloaded from the [http://developer.apple.com/ Apple Developer Connection] (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) -
 +
 
 +
<syntaxhighlight lang="bash">
 +
mv Downloads/Xcode.app /Developer/.
 +
sudo xcode-select -s /Developer/Xcode.app/Contents/Developer
 
</syntaxhighlight>
 
</syntaxhighlight>
  
or for FPC trunk:
+
==== Step 2: Xcode Command Line Tools ====
  
<syntaxhighlight lang="dos">
+
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)-
@echo on
+
 
set myroot=c:\freepascal
+
<syntaxhighlight lang="bash">
set myFPC=%myroot%\fpc\trunk
+
sudo xcode-select --install
set mybinutils=%myroot%\binutils
+
sudo xcodebuild -license accept
set PATH=%PATH%;%mybinutils%\i386-win32;%myFPC%\bin\i386-win32
 
cd %myFPC%
 
rd /s /q  %myfpc%\examples
 
svn cleanup . --remove-unversioned  --remove-ignored
 
make distclean all install INSTALL_PREFIX=%myFPC% PP=%mybinutils%\ppc386.exe DATA2INC=%myFPC%\utils\data2inc.exe
 
cd /d %myFPC%\bin\i386-win32
 
del fpc.cfg
 
fpcmkcfg -d basepath=%myFPC% -o .\fpc.cfg
 
copy fpc.exe %mybinutils%\i386-win32
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
For crosscompiler to x86_64 add the following after the first make:
+
==== Step 3: Download FPC ====
 +
 
 +
Download the Free Pascal Compiler (FPC) and FPC source from the [https://www.freepascal.org/download.html Free Pascal website]. When you arrive at the download page, select a mirror and then choose the correct version for your operating system.
 +
 
 +
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.
 +
 
 +
=== Other installation options ===
 +
 
 +
==== fpcupdeluxe ====
 +
 
 +
You could also consider using [[fpcupdeluxe]] to install FPC.
 +
 
 +
==== fink & MacPorts ====
  
<syntaxhighlight lang="dos">
+
You could also consider using one of the package managers for macOS, [http://finkproject.org/ fink] or [https://www.macports.org MacPorts], to install FPC. Their extra bonus is easy installation as well as clean removal of FPC and a huge number of other open source software packages. Fink also offers numerous [[Cross_compiling#From_macOS_to_any_using_fink|Free Pascal crosscompilers]] for many processors and operating systems.
make all OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=%myFPC% PP=%mybinutils%\ppc386.exe DATA2INC=%myFPC%\utils\data2inc.exe
+
 
make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=%myFPC% PP=%mybinutils%\ppc386.exe DATA2INC=%myFPC%\utils\data2inc.exe
+
=== Installing from source ===
</syntaxhighlight>
+
 
 +
There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2.0 branch which includes additional fixes to the released 3.2.0 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.
 +
 
 +
The source code is kept in a version control system called subversion or ''svn'' for short, and is mirrored in ''git'':
 +
 
 +
* macOS 10.5 and higher already contain a command line svn or git client if you have installed the Xcode command line utilities. You can also use fink, port or brew to get an svn client on newer macOS. SVN clients with GUI (graphical user interface) are available from [http://www.versiontracker.com Versiontracker]. A quite handy client, which integrates in Finder, is [http://scplugin.tigris.org SCPlugin].
 +
 
 +
* You also need the latest released Free Pascal Compiler version (3.2.0 as of January 2021) installed in order to be able to successfully compile the development (trunk) version.
 +
 
 +
==== FPC Trunk ====
 +
 
 +
* [[FPC_New_Features_Trunk|FPC New Features in Trunk]]
 +
* [[FPC New Features Trunk|FPC User Changes in Trunk]] - may break existing code.
  
''STEP #3: Make and install FPC''
+
Note that since FPC trunk is by definition still under development, some of the features may still change before they end up in a release version.
  
At the prompt (cmd.exe), navigate to the directory c:\freepascal and execute the script we just wrote:  
+
Create a directory where you would like to put the source (eg fpc in your home directory). You don't need to be root to do this. Any normal user can do this. Open an Applications > Utilities > Terminal and do the following:
  
<syntaxhighlight lang="dos">
+
Using git:
cd /d c:\freepascal
+
git clone git://github.com/graemeg/freepascal.git fpc
makefpc.bat
 
</syntaxhighlight>
 
  
Done!
+
Using svn:
 +
svn checkout https://svn.freepascal.org/svn/fpc/trunk fpc
  
 +
This will create a directory called 'fpc' and download the FPC source to it.
  
However, you can also download the package as a whole -- see https://www.freepascal.org/develop.html for the daily snapshots of the development (trunk) tree and the fixes (release version with additional fixes) tree.
+
To subsequently update your local source repository with the latest source changes you can simply do:
  
{{Warning|refurbishment rewriting in progress - ENDS HERE}}
+
Using git:
 +
<syntaxhighlight lang=sh>
 +
[]$ cd fpc
 +
[]$ git clean -f -d
 +
[]$ git pull
 +
</syntaxhighlight>
  
== macOS ==
+
Using svn:
 +
<syntaxhighlight lang=sh>
 +
[]$ cd fpc
 +
[]$ svn cleanup --remove-unversioned
 +
[]$ svn update
 +
</syntaxhighlight>
  
{{Note| For installation on Apple Silicon/AArch64, please refer to [[macOS_Big_Sur_changes_for_developers#ARM64.2FAArch64.2FApple_Silicon_Support|Apple Silicon Support]] for build instructions for a native Free Pascal Compiler.}}
+
To build and install FPC (the highlighted text should be all on one line):
  
{{Warning|If you are intending to also install Lazarus, please ignore these instructions and instead refer to [[Installing Lazarus on macOS]].}}
+
<syntaxhighlight lang=sh highlight=3>
 +
[]$ cd
 +
[]$ cd fpc
 +
[]$ make distclean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 +
[]$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64
 +
</syntaxhighlight>
  
=== Step 1: Download Xcode ===
+
You will also need to update the links for the compiler in <tt>/usr/local/bin</tt> which will be pointing to the previous FPC version. For example:
  
You need the Apple Developer tools, which are a part of the Xcode development environment.
+
<syntaxhighlight lang=sh>
 +
[]$ cd /usr/local/bin
 +
[]$ sudo rm ppc386
 +
[]$ sudo rm ppcx64
 +
[]$ sudo ln -s /usr/local/lib/fpc/3.3.1/ppc386
 +
[]$ sudo ln -s /usr/local/lib/fpc/3.3.1/ppcx64
 +
</syntaxhighlight>
  
Xcode 11.3.1 for use on macOS 10.14 Mojave must now be installed by downloading it from [http://developer.apple.com/ Apple Developer Connection] (ADC), which requires free registration.  Xcode 11.4.x for use on macOS 10.15 Catalina can be installed from the [https://apps.apple.com/us/genre/mac-developer-tools/id12002?mt=12 Mac App store]. 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 <tt>xcode-select</tt>.
+
Note that you will need to build a new <code>ppc386</code> compiler if you want to continue to compile 32 bit applications by replacing these lines (this may not be possible after Xcode 11.3.1 and macOS 10.14.6 Mojave because of Apple's removal of 32 bit frameworks):
  
Older systems:
+
<syntaxhighlight lang=sh>
 +
[]$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 +
[]$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64
 +
</syntaxhighlight>
  
The developer tools can be installed from the original macOS installation disks or a newer copy downloaded from the [http://developer.apple.com/ Apple Developer Connection] (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) -
+
with these two lines:
  
<syntaxhighlight lang="bash">
+
<syntaxhighlight lang=sh>
mv Downloads/Xcode.app /Developer/.
+
[]$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppc386 OS_TARGET=darwin CPU_TARGET=i386 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
sudo xcode-select -s /Developer/Xcode.app/Contents/Developer
+
[]$ sudo make install OS_TARGET=darwin CPU_TARGET=i386
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Step 2: Xcode Command Line Tools ===
+
==== FPC Fixes 3.2 ====
  
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 cannot use those Xcode internal command line tools, so do the following (it is quick and easy)-
+
Create a directory where you would like to put the source (eg <tt>fpc-fixes-3.2</tt> in your home directory). You don't need to be root to do this. Any normal user can do this. Open an Applications > Utilities > Terminal and do the following:
  
<syntaxhighlight lang="bash">
+
<syntaxhighlight lang=sh>
sudo xcode-select --install
+
[]$ svn checkout https://svn.freepascal.org/svn/fpc/branches/fixes_3_2 fpc-fixes-3.2
sudo xcodebuild -license accept
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Step 3: Download FPC ===
+
This will create a directory called <tt>fpc-fixes-3.2</tt> and download the FPC source to it.
  
Download the Free Pascal Compiler (FPC) and FPC source from the [https://www.freepascal.org/download.html Free Pascal website]. When you arrive at the download page, select a mirror and then choose the correct version for your operating system.
+
To subsequently update your local copy of the repository source with the latest source changes you can simply do:
 +
 
 +
<syntaxhighlight lang=sh>
 +
[]$ cd fpc-fixes-3.2
 +
[]$ svn cleanup --remove-unversioned
 +
[]$ svn update
 +
</syntaxhighlight>
  
These binary install kits are built by the FPC developers and track formal releases. As these install kits 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.
+
To build and install FPC (the highlighted text should be all on one line):
  
=== Other macOS installation options ===
+
<syntaxhighlight lang=sh highlight=3>
 +
[]$ cd
 +
[]$ cd fpc-fixes-3.2
 +
[]$ make distclean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 +
[]$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64
 +
</syntaxhighlight>
  
==== fpcupdeluxe ====
+
You will also need to update the links for the compiler in <tt>/usr/local/bin</tt> which will be pointing to the previous FPC version. For example:
  
You could also consider using [[fpcupdeluxe]] to install FPC.
+
<syntaxhighlight lang=sh>
 +
[]$ cd /usr/local/bin
 +
[]$ sudo rm ppc386
 +
[]$ sudo rm ppcx64
 +
[]$ sudo ln -s /usr/local/lib/fpc/fixes-3.2/ppc386
 +
[]$ sudo ln -s /usr/local/lib/fpc/fixes-3.2/ppcx64
 +
</syntaxhighlight>
  
==== fink & MacPorts ====
+
Note that you will need to build a new <code>ppc386</code> compiler if you want to continue to compile 32 bit applications by replacing these lines (this may not be possible after Xcode 11.3.1 and macOS 10.14.6 Mojave because of Apple's removal of 32 bit frameworks):
  
Alternatively, you can use one of the package managers for macOS, [http://finkproject.org/ fink] or [https://www.macports.org MacPorts], to install FPC. Their extra bonus is easy installation as well as clean removal of FPC and a huge number of other open source software packages. Fink also offers numerous [[Cross_compiling#From_macOS_to_any_using_fink | Free Pascal crosscompilers]] for many processors and operating systems.
+
<syntaxhighlight lang=sh>
 +
[]$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppc386 OS_TARGET=darwin CPU_TARGET=i386 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 +
[]$ sudo make install OS_TARGET=darwin CPU_TARGET=i386
 +
</syntaxhighlight>
  
 
== Testing the FPC Install ==
 
== Testing the FPC Install ==
Line 567: Line 672:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now compile this simple code with this command line:
+
Now compile this simple code by typing this command and then pressing {{keypress|Enter}}:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
fpc helloworld.pas <enter>
+
fpc helloworld.pas
 
</syntaxhighlight>
 
</syntaxhighlight>
  
It should very quickly make an executable called, you guessed it, "helloworld". Run this executable with this command:
+
It should very quickly make an executable called, you guessed it, "helloworld". Run this executable by typing this command and then pressing {{keypress|Enter}}:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
./helloworld <enter>
+
./helloworld
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
If that worked, well done!
 
If that worked, well done!
 +
 +
== Useful command-line switches for compiling from source ==
 +
 +
* Significantly speed up the FPC source tree compilation
 +
** <code>FPMAKEOPT="-T x"</code> (x = the number of CPU cores you have)
 +
 +
* Reduce the number of times the compiler itself gets recompiled
 +
** <code>NOWPOCYCLE=1</code>
 +
 +
* Add debug information and disable optimizations during compilation of the compiler/RTL
 +
** <code>OPT="-gl -O-"</code>
  
 
== Installing cross compilers ==
 
== Installing cross compilers ==
Line 587: Line 703:
 
== See also ==
 
== See also ==
  
* [[FPC|FPC Wiki Documentation]]
+
* [[FPC|FPC Wiki Documentation]].
* [https://www.freepascal.org/docs.html FPC Official Documentation]
+
* [https://www.freepascal.org/docs.html FPC Official Documentation].
* [[FPC_New_Features_Trunk|FPC New Features in Trunk]]
+
* [[FPC_New_Features_3.2.0|FPC 3.2.0 New Features]].
 +
* [[User_Changes_3.2.0|FPC 3.2.0 User Changes]] - may break existing code.
 +
* [[FPC_New_Features_Trunk|FPC New Features in Trunk]].
 
* [[FPC New Features Trunk|FPC User Changes in Trunk]] - may break existing code.
 
* [[FPC New Features Trunk|FPC User Changes in Trunk]] - may break existing code.
  
 
[[Category:FPC]]
 
[[Category:FPC]]
 
[[Category:Install]]
 
[[Category:Install]]

Latest revision as of 03:55, 2 May 2021

English (en) 中文(中国大陆)‎ (zh_CN)

Overview

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 (tar, exe, rpm, dmg, pkg files). In addition, versions of FPC are provided (including rpm and deb files) from the Lazarus download site. Linux users can almost certainly find FPC in their distribution's repositories but may find that it is outdated.

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.

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.

Linux

FPC Binary Packages

Note-icon.png

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.

With the recent release of FPC 3.2.0, only a few distributions will have the new FPC compiler in its repositories. You can do one of -

FPC Tar Balls

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.

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.

Note-icon.png

Note: A tar install does not resolve dependencies, if they are not already present, first install binutils, make, gcc.

cd
mkdir -p bin/FPC/Tars
mkdir bin/FPC/SRC
mkdir bin/FPC/fpc-3.2.0
cd bin/FPC/Tars
# download src and compiler tars, change for different CPU (or Mac ?) 
wget https://sourceforge.net/projects/freepascal/files/Source/3.2.0/fpc-3.2.0.source.tar.gz
wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/fpc-3.2.0-x86_64-linux.tar
tar xf fpc-3.2.0-x86_64-linux.tar
cd fpc-3.2.0-x86_64-linux
./install.sh
# when asked where to install, enter $HOME/bin/FPC/fpc-3.2.0, accept all defaults after that.

cd ../../SRC
tar xzf ../Tars/fpc-3.2.0.source.tar.gz

# Set a path to where the compiler is, add line at end of .bashrc, if you don't use bash, adjust !
# (! e.g. Use ~/.profile instead of ~/.bashrc so that the path is available also in Lazarus IDE.)
echo "PATH=\"\$HOME/bin/FPC/fpc-3.2.0/bin\":\"\$PATH\"" >> ~/.bashrc
source ~/.bashrc

# trivial test
cd 
fpc -iV
Note-icon.png

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 -

wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/fpc-3.2.0.arm-linux.tar
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.

FPC sources

The FPC source files are stored in a Subversion (SVN) repository (https://svn.freepascal.org/svn/fpc/trunk) and mirrored in a Git repository (git://github.com/graemeg/freepascal.git). The repository keeps track of all the changes by developers in the source tree. Once you have the sources, please see Installing from source under BSD/Linux for instructions on how to install them.

Update from the source repository using SVN or Git

The SVN or Git repository has been made accessible for everyone, with read-only access. This means that you can directly access the code, and you will have really the last-minute sources available. It is also a method which requires less bandwidth once you have done the first download (checkout in SVN lingo; clone in Git lingo).

Getting the source

First, you need to have an SVN or Git client installed. Use your package manager, install a tool like TortoiseSVN on Windows, or look at the Subversion web site or the Git webs site for more details and client downloads.

Using command line svn: change directory (cd) to the parent directory of your development area, eg To retrieve the full source repository for the first time into an fpc subdirectory under your home directory, type:

cd ~
svn checkout http://svn.freepascal.org/svn/fpc/trunk fpc

Note: FreeBSD includes the svnlite client in the base system which you can use instead of installing the full Subversion svn client.

Using command line git: change directory (cd) to the parent directory of your development area, eg To retrieve the full source repository for the first time into an fpc subdirectory under your home directory, type:

cd ~
git clone git://github.com/graemeg/freepascal.git fpc

To update the sources which were downloaded (checked out/cloned) above:

Using svn:

cd ~
svn cleanup --remove-unversioned
svn update fpc

Using git:

cd ~
git clean -f -d
git pull

Getting a separate branch

If the current trunk version is in a state of rapid change and unsuitable for much use unless you want to work on the compiler itself, you can stay on a version that is updated with fixes. To do this, you have to find out a stable branch that you want to track instead of the default trunk development version.

The example below shows how you can track the fixes_3_2 version; of course replace as needed depending on what branch you want to track.

This example keeps the fixes in another directory under your home directory - it wouldn't make sense to put two versions of the source in one directory...

Using svn:

cd ~
svn checkout http://svn.freepascal.org/svn/fpc/branches/fixes_3_2 fpc_fixes_3_2

Update as usual:

cd ~
svn cleanup --remove-unversioned
svn update fpc_fixes_3_2

Note: There is no Git repository for fixes_3_2.

Documentation sources

The documentation sources are in a separate repository called fpcdocs, so the command to get them is:

cd ~
svn checkout http://svn.freepascal.org/svn/fpcdocs/trunk fpcdocs

If you want to learn more about subversion, read this excellent Subversion book which is also available online in different formats for free.

For more information, see the Free Pascal website.

Compiling the FPC source

  • First install the release FPC from rpm/deb or tar balls as described above.
  • Get FPC sources (trunk) as described above.
  • Make FPC sources with (execute in the source (trunk) directory)
make clean all
make install INSTALL_PREFIX=install/to/directory

Decide about install/to/directory and also add options that you need.

  • 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.
  • 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
cd install/to/directory/lib/fpc
mkdir etc
fpcmkcfg -d basepath="install/to/directory/lib/fpc/\$fpcversion" -o etc/fpc.cfg

FreeBSD

Note-icon.png

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.

Installing from the ports collection

The FreeBSD ports collection has FPC v3.2.0 version in /usr/ports/lang/fpc. FPC is scattered over 105(!) packages. The FPC source is now installed by default; it previously needed to be copied and uncompressed from /usr/ports/distfiles/freepascal.

This must be done as root.

# cd /usr/ports/lang/fpc && make install && make clean

Once FPC is installed you can check if it's working by simply running as a normal user:

$ fpc test

which should produce output similar to this:

 Free Pascal Compiler version 3.2.0 [2020/11/14] for x86_64
 Copyright (c) 1993-2020 by Florian Klaempfl and others
 Target OS: FreeBSD for x86-64
 Compiling test
 Fatal: Cannot open file "test"
 Fatal: Compilation aborted
 Error: /usr/local/bin/ppcx64 returned an error exitcode

To fix a linking issue (as of FreeBSD 12.2, 29 Dec 2020), you must also install the GNU devel/binutils if not already installed and then use a symbolic-link from /usr/local/bin/ld.bfd to /bin/ld.bfd.

Installing from tar

Select the appropriate 32 bit/64 bit tar file based on your system. For x86_64 64-bit FreeBSD, download from x86_64. For i386 32-bit FreeBSD, download from i386.

To install Free Pascal from a terminal:

$ fetch ftp://ftp.freepascal.org/pub/fpc/dist/3.2.0/x86_64-freebsd/fpc-3.2.0.x86_64-freebsd11.tar
$ tar -xf fpc-3.2.0.x86_64-freebsd11.tar
$ cd fpc-3.2.0.x86_64-freebsd
$ bash install.sh

Replace the desired Free Pascal version (3.0.4, 3.2.0 or 3.3.1) and architecture (x86_64 or i386) as required.

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.

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:

uses cthreads;
begin
    writeln('hello'); 
end.

The executable generated for this program will cause a segmentation fault when run. To fix this issue, you need to install the GNU linker:

root# pkg install binutils

and add a symbolic-link from /usr/local/bin/ld.bfd to /bin/ld.bfd.

OpenBSD

Installing from tar

Select the appropriate 32 bit/64 bit tar file based on your system. For x86_64 64-bit OpenBSD, download from x86_64. For i386 32-bit OpenBSD, download from i386.

To install Free Pascal from a terminal:

$ wget ftp://ftp.freepascal.org/pub/fpc/dist/3.2.0/x86_64-openbsd/fpc-3.2.0.x86_64-openbsd.tar
$ tar -xf fpc-3.2.0.x86_64-openbsd.tar
$ cd fpc-3.2.0.x86_64-openbsd
$ bash install.sh

Replace the desired Free Pascal version (3.0.4, 3.2.0 or 3.3.1) and architecture (x86_64 or i386) as required.

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.

Installing from source on BSD/Linux

Effectively, you need:

1. A file with all FPC sources (https://sourceforge.net/projects/freepascal/files/Source/3.2.0/fpc-3.2.0.source.tar.gz).

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.

FPC build process:

  • Fetch necessary files (starting compiler), FPC source file or source svn directory
  • If using FPC source files: extract/de-tgz in work directory,
  • Build: enter work/fpc/ and run:
# Linux use:   
export MAKE=`which make` ; echo $MAKE 
# FreeBSD use (default csh, or tcsh):
set MAKE=`which gmake` ; echo $MAKE
# FreeBSD use (bash):
export MAKE=`which gmake` ; echo $MAKE
$MAKE all OPT='-gl' FPC=/path/to/startingcompiler-name-ppcx64
# $MAKE is make on Linux and gmake on BSD 
# /path/to/ can be omitted when ppc386 (32 bit) or ppcx64 (64 bit) is in the path
  • Install FPC. Again in work/fpc, run
$MAKE install FPC=compiler/ppcx64 PREFIX=$THEPREFIX
#replace the FPC=compiler/ppcx64 (or ppc386 for 32 bit) with the relevant compiler if not on Intel x86
#THEPREFIX= usually is /usr/local or just /usr, but eg on NetBSD it is /usr/pkg for ports)
  • Create a symlink:
ln -s $THEPREFIX/lib/fpc/3.2.0/ppcx64 $THEPREFIX/bin/ppcx64
  • Install sources:
$MAKE install sourceinstall PREFIX=$THEPREFIX
  • Create a symlink for default FPC source path:
ln -sf $THEPREFIX/share/src/3.2.0/fpc /usr/share/fpcsrc
  • Set up fpc.cfg configuration file:
$THEPREFIX/lib/fpc/3.2.0/samplecfg $THEPREFIX/lib/fpc/3.2.0 $ETCDIR
  • 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.

Notes:

  • 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
    find . >ll
    
  • $THEPREFIX and $ETCDIR should be user configurable. Otherwise local installs aren't possible.
  • BSDHIER=1 on all make commands forces BSD hierarchy conventions.

Windows

Installing an FPC release with the Windows installer

Warning-icon.png

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.

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.0 - this release contains the current 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:

  • Choose an installation location for FPC (suggested C:\FPC\3.2.0)
  • Choose installation type (recommended Full Installation)
  • Choose file associations, configuration file creation etc
  • Install
  • View README

Installing from source

Installing from source with a command line Subversion (svn) 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.

Obtaining the source with a command line svn client

The easiest way to get the Free Pascal Compiler source is by using a Subversion (svn) client. The exact commands may vary between svn clients; the commands given below are for the command line Subversion client downloadable from SourceForge - win32svn.

Source for a release version of FPC

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:

C:\Users\you> cd \
C:\> mkdir Source
C:\> cd Source

Now type issue the following command at a command prompt:

C:\Source> svn checkout https://svn.freepascal.org/svn/fpc/tags/release_3_2_0 fpc-3.2.0

Wait while the Subversion repository is downloaded to the fpc-3.2.0 directory in your newly created Source directory. This can take a while... have a look at the helpful Free Pascal Forums while you wait :-) You may also like to read the excellent How to use the Forum Wiki article which explains how to get answers to pesky questions quickly. New Forum users are always welcome.

Source for a non-release version of FPC

There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2.0 branch which includes additional fixes to the released 3.2.0 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.

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:

For the Fixes branch of FPC 3.2.0

C:\Source> svn checkout https://svn.freepascal.org/svn/fpc/branches/fixes_3_2_0 fpc-fixes-3.2.0

For the Development (trunk) branch of FPC

C:\Source> svn checkout https://svn.freepascal.org/svn/fpc/trunk fpc-trunk

Hint: To update your local copy of the repository with subsequent changes, you need only do:

For the Fixes branch of FPC 3.2.0

C:\> cd C:\Source\fpc-fixes-3.2.0
C:\Source\fpc-fixes-3.2.0> svn clean --remove-unversioned --remove-ignored
C:\Source\fpc-fixes-3.2.0> svn update

For the Development (trunk) branch of FPC

C:\> cd C:\Source\fpc-trunk
C:\Source\fpc-trunk> svn clean --remove-unversioned --remove-ignored
C:\Source\fpc-trunk> svn update

Obtaining the source with the GUI TortoiseSVN client

The first thing you will probably need to do is download the GUI TortoiseSVN Subversion client from TortoiseSVN website Download file area if you do not already have it available.

After downloading the appropriate Windows installer and installing it, you are ready to begin. You will notice that TortoiseSVN has added a number of shortcuts to the File Explorer context menu so that you can work easily with svn without needing to use the command prompt.

Source for a release version of FPC

To download the latest release version Free Pascal Compiler source from the Subversion repository, first create the directory in which you'd like to keep the source. Any normal user can do this:

  • Open File Explorer and navigate to "Local Disk C:"
  • Choose Home > New folder in File Explorer and create a directory for the FPC source (eg C:\Source).
  • Right click in File Explorer in your newly created directory and you should see an entry for "SVN Checkout..." in the context menu, choose this entry and you will be presented with a TortoiseSVN Checkout Dialog.
  • Fill in the "URL of the Repository" field with this URL: https://svn.freepascal.org/svn/fpc/tags/release_3_2_0
  • In the "Checkout directory" field add fpc-3.2.0 to the existing C:\Source\ in the field so you end up with C:\Source\fpc-3.2.0. This is the directory which will house your local copy of the source repository.
  • Leave the other fields at their default and click OK.
  • Now you will be presented with a new dialog which shows the progress of the checkout... wait while the Subversion repository is downloaded to the fpc-3.2.0 directory in your newly created Source directory. This can take a while... have a look at the helpful Free Pascal Forums while you wait :-) You may also like to read the excellent How to use the Forum Wiki article which explains how to get answers to pesky questions quickly. New Forum users are always welcome.
Source for a non-release version of FPC

There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2.0 branch which includes additional fixes to the released 3.2.0 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.

The instructions are the same as for a release version of the Free Pascal Compiler given above, except that you will need to replace the "URL of the Repository" and "Checkout directory" fields with the appropriate values set out below:

For the Fixes branch of FPC

 Repository URL: https://svn.freepascal.org/svn/fpc/branches/fixes_3_2_0 
 Checkout Directory: C:\Source\fpc-fixes-3.2.0

For the Development (trunk) branch of FPC

 Repository URL: https://svn.freepascal.org/svn/fpc/trunk 
 Checkout Directory: C:\Source\fpc-trunk

Updating your local repository

To update your local copy of the repository with subsequent source changes:

  • Open File Explorer, navigate to your C:\Source and right-click on the fpc-fixes-3.2.0 or fpc-trunk directory.
  • You should see an entry for "TortoiseSVN", if you hover over it, another longer context menu will be presented from which you should choose "Clean up...". In the Cleanup dialog, check both "Delete unversioned files and folders" and "Delete ignored files and folders".
  • Now right-click on the fpc-fixes-3.2.0 or fpc-trunk directory again and you should see an entry for "SVN Update" in the context menu, choose this entry and you will be presented with a TortoiseSVN Update Dialog and the update will start without you needing to do anything else. When the update finishes, click OK to exit.

Obtaining a bootstrap compiler

To obtain a bootstrap Free Pascal Compiler, download the distribution package fpc-3.2.0.i386-win32.exe 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.

Then restart windows.

Compiling the FPC source

Before you start

  • 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.0 release files are placed in C:\FPC\3.2.0. 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.
  • 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):
 fpc windows make.png
  • If you need to change your path so that the correct make.exe is found, you can either do it temporarily or permanently.
    • 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.0\bin\i386-win32, at a command prompt type:
      C:\Source> set PATH=C:\FPC\3.2.0\bin\i386-win32;%PATH%
      
    • 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.0\bin\i386-win32 occurs first.

Instructions

  • At a command prompt, navigate to your local FPC source directory (eg C:\Source\fpc-3.2.0) by typing:
C:\> cd Source\fpc-3.2.0
  • Compile the FPC source with:
C:/Source/fpc-3.2.0> make distclean all
  • To overwrite an existing FPC installation in, for example, C:\FPC) type:
C:/Source/fpc-3.2.0> make install PREFIX=C:\FPC
  • If you also need the cross-compiler to x86_64, type the following commands which will compile the cross-compiler and then install it:
C:/Source/fpc-3.2.0> make all OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=C:\FPC\3.2.0 PP=C:\FPC\3.2.0\bin\i386-win32\ppc386.exe DATA2INC=C:\FPC\3.2.0\bin\i386-win32\data2inc.exe

C:/Source/fpc-3.2.0> make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=C:\FPC\3.2.0 PP=C:\FPC\3.2.0\bin\i386-win32\ppc386.exe DATA2INC=C:\FPC\3.2.0\bin\i386\win32\data2inc.exe

The cross-compiler to compile programs for Windows 64 bit may now be found here: C:\FPC\3.2.0\bin\i386-win32\ppcrossx64.

Done!

macOS

Warning-icon.png

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.

Note-icon.png

Note: For installation on Apple Silicon/AArch64, please refer to Apple Silicon Support for build instructions for a native Free Pascal Compiler.

Installing an FPC release from the official macOS packages

Step 1: Download Xcode (optional)

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:

  • the SDKs for iOS, iPadOS, watchOS and tvOS; or
  • to validate and upload apps to the Mac App Store; or
  • to notarise apps for distribution outside of the Mac App Store.

Xcode 11.3.1 for use on macOS 10.14 Mojave must now be installed by downloading it from Apple Developer Connection (ADC), which requires free registration. Xcode 11.4.x for use on macOS 10.15 Catalina can be installed from the Mac App store. 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.

Older systems:

The developer tools can be installed from the original macOS installation disks or a newer copy downloaded from the Apple Developer Connection (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) -

mv Downloads/Xcode.app /Developer/.
sudo xcode-select -s /Developer/Xcode.app/Contents/Developer

Step 2: Xcode Command Line Tools

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)-

sudo xcode-select --install
sudo xcodebuild -license accept

Step 3: Download FPC

Download the Free Pascal Compiler (FPC) and FPC source from the Free Pascal website. When you arrive at the download page, select a mirror and then choose the correct version for your operating system.

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.

Other installation options

fpcupdeluxe

You could also consider using fpcupdeluxe to install FPC.

fink & MacPorts

You could also consider using one of the package managers for macOS, fink or MacPorts, to install FPC. Their extra bonus is easy installation as well as clean removal of FPC and a huge number of other open source software packages. Fink also offers numerous Free Pascal crosscompilers for many processors and operating systems.

Installing from source

There are two current non-release branches of the Free Pascal Compiler: the development (trunk) branch and the Fixes 3.2.0 branch which includes additional fixes to the released 3.2.0 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.

The source code is kept in a version control system called subversion or svn for short, and is mirrored in git:

  • macOS 10.5 and higher already contain a command line svn or git client if you have installed the Xcode command line utilities. You can also use fink, port or brew to get an svn client on newer macOS. SVN clients with GUI (graphical user interface) are available from Versiontracker. A quite handy client, which integrates in Finder, is SCPlugin.
  • You also need the latest released Free Pascal Compiler version (3.2.0 as of January 2021) installed in order to be able to successfully compile the development (trunk) version.

FPC Trunk

Note that since FPC trunk is by definition still under development, some of the features may still change before they end up in a release version.

Create a directory where you would like to put the source (eg fpc in your home directory). You don't need to be root to do this. Any normal user can do this. Open an Applications > Utilities > Terminal and do the following:

Using git:

git clone git://github.com/graemeg/freepascal.git fpc

Using svn:

svn checkout https://svn.freepascal.org/svn/fpc/trunk fpc

This will create a directory called 'fpc' and download the FPC source to it.

To subsequently update your local source repository with the latest source changes you can simply do:

Using git:

 []$ cd fpc
 []$ git clean -f -d
 []$ git pull

Using svn:

 []$ cd fpc
 []$ svn cleanup --remove-unversioned
 []$ svn update

To build and install FPC (the highlighted text should be all on one line):

 []$ cd
 []$ cd fpc
 []$ make distclean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64

You will also need to update the links for the compiler in /usr/local/bin which will be pointing to the previous FPC version. For example:

 []$ cd /usr/local/bin
 []$ sudo rm ppc386
 []$ sudo rm ppcx64
 []$ sudo ln -s /usr/local/lib/fpc/3.3.1/ppc386
 []$ sudo ln -s /usr/local/lib/fpc/3.3.1/ppcx64

Note that you will need to build a new ppc386 compiler if you want to continue to compile 32 bit applications by replacing these lines (this may not be possible after Xcode 11.3.1 and macOS 10.14.6 Mojave because of Apple's removal of 32 bit frameworks):

 []$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64

with these two lines:

 []$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppc386 OS_TARGET=darwin CPU_TARGET=i386 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=i386

FPC Fixes 3.2

Create a directory where you would like to put the source (eg fpc-fixes-3.2 in your home directory). You don't need to be root to do this. Any normal user can do this. Open an Applications > Utilities > Terminal and do the following:

 []$ svn checkout https://svn.freepascal.org/svn/fpc/branches/fixes_3_2 fpc-fixes-3.2

This will create a directory called fpc-fixes-3.2 and download the FPC source to it.

To subsequently update your local copy of the repository source with the latest source changes you can simply do:

 []$ cd fpc-fixes-3.2
 []$ svn cleanup --remove-unversioned
 []$ svn update

To build and install FPC (the highlighted text should be all on one line):

 []$ cd
 []$ cd fpc-fixes-3.2
 []$ make distclean all FPC=/usr/local/lib/fpc/3.2.0/ppcx64 OS_TARGET=darwin CPU_TARGET=x86_64 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=x86_64

You will also need to update the links for the compiler in /usr/local/bin which will be pointing to the previous FPC version. For example:

 []$ cd /usr/local/bin
 []$ sudo rm ppc386
 []$ sudo rm ppcx64
 []$ sudo ln -s /usr/local/lib/fpc/fixes-3.2/ppc386
 []$ sudo ln -s /usr/local/lib/fpc/fixes-3.2/ppcx64

Note that you will need to build a new ppc386 compiler if you want to continue to compile 32 bit applications by replacing these lines (this may not be possible after Xcode 11.3.1 and macOS 10.14.6 Mojave because of Apple's removal of 32 bit frameworks):

 []$ make clean all FPC=/usr/local/lib/fpc/3.2.0/ppc386 OS_TARGET=darwin CPU_TARGET=i386 OPT="-XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/"
 []$ sudo make install OS_TARGET=darwin CPU_TARGET=i386

Testing the FPC Install

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) and copy this very short program and save it as the file helloworld.pas:

program helloworld;
begin
	writeln('hello world !');
end.

Now compile this simple code by typing this command and then pressing Enter:

fpc helloworld.pas

It should very quickly make an executable called, you guessed it, "helloworld". Run this executable by typing this command and then pressing Enter:

./helloworld

If that worked, well done!

Useful command-line switches for compiling from source

  • Significantly speed up the FPC source tree compilation
    • FPMAKEOPT="-T x" (x = the number of CPU cores you have)
  • Reduce the number of times the compiler itself gets recompiled
    • NOWPOCYCLE=1
  • Add debug information and disable optimizations during compilation of the compiler/RTL
    • OPT="-gl -O-"

Installing cross compilers

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 Win32, FreeBSD or Linux. For details on how to do this, see Cross Compiling.

See also