Difference between revisions of "Installing the Free Pascal Compiler/zh CN"

From Lazarus wiki
Jump to navigationJump to search
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{LanguageBar}}
 
{{LanguageBar}}
  
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.
+
这里有一个如何安装和构建FreePascal编译器的广泛讨论,网址:http://www.stack.nl/~marcov/buildfaq.pdf - 对于一些用户来说,它可能有点太过于详细了,但是它是非常全面的。
  
== 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.
+
这里有很多方法来在你的系统上安装FPC。当前发布版本,trunk版本,有时beta版本和RC版本也可以从FPC网站https://sourceforge.net/projects/freepascal/files/ (tar, exe, rpm, dmg 文件)直接获得。另外,从Lazarus的下载网站中也提供了FPC的版本(包括rpm和deb文件),Lazarus网址http://sourceforge.net/projects/lazarus/files/。 Linux用户差不多都能从Linux发行版的存储库中找到FPC,但是可能会发现FPC是过时的版本。
  
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.
+
从源文件构建FPC也是可能的,通常每个发布版本都可以使用先前的发布版本构建。在系统安装应用程序空间中(通常需root几或administrator访问权限)或在你自己的用户控件中安装FPC都是能做到的。这些取决于您的特定的操作系统环境。
  
 
== Linux ==
 
== Linux ==
  
=== FPC Binary Packages ===
+
=== FPC二进制文件软件包 ===
  
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 -
+
尽管最新的FPC3.2.0已经发布,但是只有少数发行版的存储库中存在新的FPC编译器。你可以做一个FPC -
  
* If you use '''rpm packages''', you can find FPC320 in https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/ or more generally in https://www.freepascal.org/download.html  You might install using a command like -<syntaxhighlight lang="bash">yum localinstall fpc-3.2.0-1.x86_64.rpm
+
* 如果你使用'''rpm软件包''',你可以在https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/中找到FPC320,或者在https://www.freepascal.org/download.html中的更大范围内查找,你可以使用一个命令来安装,像 -
// or perhaps
+
<syntaxhighlight lang="bash">yum localinstall fpc-3.2.0-1.x86_64.rpm
 +
// 或者
 
rpm -Uvh fpc-3.2.0-1.x86_64.rpm</syntaxhighlight>
 
rpm -Uvh fpc-3.2.0-1.x86_64.rpm</syntaxhighlight>
* 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)-<syntaxhighlight lang="bash">apt install ./fpc-laz_3.2.0-1_amd64.deb     </syntaxhighlight>
+
* 如果你使用'''deb软件包''',尝试一个可用的软件包,但是它并不是与Lazarus(https://sourceforge.net/projects/lazarus/files/) 绑定在一起。使用gdebi安装,也或者这个命令(注意在文件名称前面的./ ,如果你不使用一个精确的路径到文件名称,apt将搜索它自己的官方存储库,而不是你想要的)-  
 +
<syntaxhighlight lang="bash">apt install ./fpc-laz_3.2.0-1_amd64.deb</syntaxhighlight>
  
=== FPC Tar Balls ===
+
=== FPC的Tar包 ===
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.
+
另一个选项是从一个tar包安装,一种简单并且可能更有用的模型。这些tar包可广泛地用于类Unix系统中。你需要为你的操作系统和CPU来下载恰当的二进制文件tar包,并且你也可能需要所有操作系统/CPU都通用的源文件 文件。你可以在你自己的空间中安装FPC,而不是作为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.
+
这里有一系列的命令,而不是一个脚本,这些命令将在一个64位Linux系统上安装FPC。这些命令可以编写成脚本,但是需要健全性和错误检查。注意,我喜欢在我的$HOME/bin中安装像这样的大小,如果你喜欢在$HOME中安装东西,甚至会更简单一些,我确信你可以看到其中的不同点。
  
{{Note| A tar install '''does not resolve dependencies''', if they are not already present, first install binutils, make, gcc. }}
+
{{Note| 一 次tar包安装'''不会解决依赖关系''',如果这些依赖还不存在,首先安装binutils, make, gcc。}}
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 32: Line 34:
 
mkdir bin/FPC/SRC
 
mkdir bin/FPC/SRC
 
cd bin/FPC/Tars
 
cd bin/FPC/Tars
# download src and compiler tars, change for different CPU (or Mac ?)  
+
# 下载源文件和编译器tar包,为不同的CPU(或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/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
 
wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/fpc-3.2.0-x86_64-linux.tar
Line 38: Line 40:
 
cd fpc-3.2.0-x86_64-linux
 
cd fpc-3.2.0-x86_64-linux
 
./install.sh
 
./install.sh
# when asked where to install, enter $HOME/bin/FPC/fpc-3.2.0, accept all defaults after that.
+
# 当询问在何处安装时,输入$HOME/bin/FPC/fpc-3.2.0 ,并在此之后接受所有的默认值。
  
 
cd ../../SRC
 
cd ../../SRC
 
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 !  
+
# .bashrc的结尾处,添加并设置一个编译器在哪里的路径,如果你不使用bash,相应地调整!  
 
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
  
# trivial test
+
# 不重要的测试
 
cd  
 
cd  
 
fpc -iV
 
fpc -iV
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{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 - <syntaxhighlight>wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/fpc-3.2.0.arm-linux.tar</syntaxhighlight> 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.}}
+
{{Note|上面第二个的wget假设你正在使用的是一个amd64 (AMD或Intel)类型的机器,其它的平台需要一个不同的tar包。例如,针对一个'''Raspberry Pi''',你可以使用:-  
 +
<syntaxhighlight>wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/fpc-3.2.0.arm-linux.tar</syntaxhighlight>
 +
这个tar包拥有armhf的32位编译器。顺便说一句,Raspberry Pi可能需要你增加swap空间到至少1G。如果你计划稍后使用FPC构建一些大型应用程序的话。}}
  
=== FPC sources ===
+
=== FPC源文件 ===
  
The FPC source files are stored in a Subversion (SVN) repository that keeps track of all changes of the source tree. Once you have the sources, please see [[#Installing_from_source_on_BSD.2FLinux|Installing from source under BSD/Linux]] for instructions on how to install them.
+
FPC源文件文件存储在一个Subversion (SVN)存储库中,该存储库保持跟踪源文件树的所有更改。在你拥有源文件后,关于如何安装它们是说明,请查看[[#Installing_from_source_on_BSD.2FLinux|BSD/Linux下从源文件安装]]
  
==== Update from the source repository using SVN ====
+
==== 使用SVN从源文件存储库更新 ====
  
The SVN 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).
+
SVN存储库已经为每个人提供了只读可访问权限。这意味你可以直接访问代码,并且你将获得最新的源文件。这是一个方法,它需要较少的宽带,在你完成第一次下载后(在SVN中签出)
  
==== Getting the source ====
+
==== 获取源文件 ====
  
First, you need to have an SVN client installed. Use your package manager, install a tool like TortoiseSVN on Windows, or look at [http://subversion.tigris.org/ the web site] for more details.
+
首先,你需要一个已经安装的SVN客户端。使用你的软件包管理器,安装一个工具,像在Windows上的TortoiseSVN ,更多信息查看[http://subversion.tigris.org/ 网页]
  
Using command line SVN: change directory (cd) to the parent directory of your development area, eg
+
使用命令行SVN:更改目录(cd)到你开发区域的父目录,例如,为了首次在你的home目录下的一个fpc子目录下,索回完整的源文件存储库,输入:
To retrieve the full source repository for the first time into an fpc subdirectory under your home directory, type:
 
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 74: Line 77:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
To update the sources which were downloaded (checked out) above:
+
为更新上面已下载(已签出的)的源文件:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 81: Line 84:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==== 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.
+
如果当前的trunk版本处于一个快速变化的状态,不适合多用。除非你想在编译器本身上工作,你可以停留在一个带有fixes分支的更新版本上。为此,你必需找到一个你想要跟踪的稳定'''分支''',而不是默认的'''trunk'''开发版本。
  
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.
+
下面的示例向你展示如何跟踪fixes_3_2版本;当然,可根据你想跟踪的的分支来进行替换。
 
+
Th这个示例将在你的home目录下的另外一个目录下保留fixes分支 - 在一个目录中放置源文件的两个版本是没有意义的...
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...
 
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 94: Line 96:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Update as usual:
+
照例更新:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 101: Line 103:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==== Documentation sources ====
+
==== 文档源文件 ====
  
The documentation sources are in a separate repository called fpcdocs, so the command to get them is:
+
文档源文件位于一个名称为fpcdocs的单独的存储库中,因此获取它们的命令是:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 110: Line 112:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
If you want to learn more about subversion, read this excellent [http://svnbook.red-bean.com/ Subversion book] which is also available online in different formats for free.
+
如果你想要学习更多关于subversion的知识,阅读这本极好的[http://svnbook.red-bean.com/ Subversion书籍],它也可以在网上以不同的格式免费获取。
  
For more information, see the [https://www.freepascal.org/develop.html Free Pascal website].
+
更多信息,查看[https://www.freepascal.org/develop.html Free Pascal网站]
  
 
== FreeBSD ==
 
== FreeBSD ==
  
{{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}}
+
{{Note|如果你也希望安装Lazarus,你可以忽略下面安装FPC的步骤,因为Lazarus的port集合将为你 安装FPC}}
  
=== Installing from the ports collection ===
+
=== 从port集合安装 ===
  
The FreeBSD ports collection has FPC v3.0.4 version in <tt>/usr/ports/lang/fpc</tt>. FPC is scattered over 38 (!) packages. The FPC source is now installed by default; it previously needed to be copied and uncompressed from <tt>/usr/ports/distfiles/freepascal</tt>.
+
FreeBSD的port集合在<tt>/usr/ports/lang/fpc</tt>中有FPC v3.0.4版本。FPC 分散在38 (!)软件包中。FPC源文件现在已经默认安装了;它以前需要从<tt>/usr/ports/distfiles/freepascal</tt>中复制和解压缩。
  
This must be done as root.
+
这必需以root的身份来完成。
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 128: Line 130:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Once FPC is installed you can check if it's working by simply running as a normal user:
+
在安装FPC后,你只需要以一个普通用户的身份来检查它是否工作,运行:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 134: Line 136:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
which should produce output similar to this:
+
这应该会产生一个类似于这样的输出:
  
 
   Free Pascal Compiler version 3.0.4 [2020/06/14] for x86_64
 
   Free Pascal Compiler version 3.0.4 [2020/06/14] for x86_64
Line 144: Line 146:
 
   Error: /usr/local/bin/ppcx64 returned an error exitcode
 
   Error: /usr/local/bin/ppcx64 returned an error exitcode
  
=== Installing from tar ===
+
=== 从tar包安装 ===
  
Select the appropriate 32 bit/64 bit tar file based on your system. For x86_64 64-bit FreeBSD, download from [https://www.freepascal.org/down/x86_64/freebsd.html x86_64]. For i386 32-bit FreeBSD, download from [https://www.freepascal.org/down/i386/freebsd.html i386].
+
根据你的系统选择恰当的32位/64位的tar包文件。对于x86_64的64位的FreeBSD,从[https://www.freepascal.org/down/x86_64/freebsd.html x86_64]下 载。对于i386的32位的FreeBSD,从[https://www.freepascal.org/down/i386/freebsd.html i386]下载。
  
To install Free Pascal from a terminal:
+
为安装Free Pascal,从一个终端中运行:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 157: Line 159:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Replace the desired Free Pascal version (3.0.4, 3.2.0 or 3.3.1) and architecture (X86_64 or i386) as required.
+
根据需要替换Free Pascal版本(3.0.4, 3.2.0或3.3.1) 和架构(X86_64或i386)
  
If you want to install the Free Pascal Compiler globally, for example in <tt>/usr/local</tt>, run the install.sh script as root.
+
如果你想全局安装Free Pascal Compiler,例如在<tt>/usr/local</tt>中,作为 root用户身份运行install.sh脚本。
  
If you are on FreeBSD 12 or newer, the default linker is the <code>lld</code>. This may cause problems if you have code that uses, for example, the cthreads unit as in the following program:
+
如果你在FreeBSD 12或更新的版本,默认的链接器是<code>lld</code>。这可能会导致问 题,例如,如果你的代码使用 cthreads单元,像下面的程序一样:
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
Line 170: Line 172:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The executable generated for this program will cause a segmentation fault when run. To fix this issue, you need to install the GNU linker:
+
为这个程序生成的可执行文件在运行时将导致一个分段错误。为修复这个问题,你需要安装GNU的链接器:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 176: Line 178:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
and make sure that <tt>/usr/local/bin/</tt> occurs in your PATH environment variable before <tt>/usr/bin/</tt>.
+
并确保<tt>/usr/local/bin/</tt>存在于你的PATH环境变量中,并在/tt>/usr/bin/</tt>之前
  
== Installing from source on BSD/Linux ==
+
== 在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).
+
1. 一个包含所有FPC源文件的文件(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.
+
2. 一个启动(自举)FPC编译器。一个FPC发布版本总是可以由先前发布的FPC版本所构建,FPC trunk版本也总是可以由当前的FPC发布版本所构建。你可以现在一个自举Free Pascal编译器或者使用你发行版的软件包管理器/软件系统来安装一个编译器。
  
FPC build process:
+
FPC构建过程:
  
* Fetch necessary files (starting compiler), FPC source file or source svn directory
+
* 获取编译的文件(启动编译器),FPC源文件文件或源文件svn目录
* If using FPC source files: extract/de-tgz in work directory,
+
* 如果使用FPC源文件文件:在工作中提取/解压缩文件
* Build: enter work/fpc/ and run:
+
* 构建:进入工作的/fpc/目录中并运行:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
# Linux use: 
+
# Linux使用
 
export MAKE=`which make` ; echo $MAKE  
 
export MAKE=`which make` ; echo $MAKE  
# FreeBSD use (default csh, or tcsh):
+
# FreeBSD使用(默认csh,或tcsh)
 
set MAKE=`which gmake` ; echo $MAKE
 
set MAKE=`which gmake` ; echo $MAKE
# FreeBSD use (bash):
+
# FreeBSD使用(bash)
 
export MAKE=`which gmake` ; echo $MAKE
 
export MAKE=`which gmake` ; echo $MAKE
 
$MAKE all OPT='-gl' FPC=/path/to/startingcompiler-name-ppcx64
 
$MAKE all OPT='-gl' FPC=/path/to/startingcompiler-name-ppcx64
# $MAKE is make on Linux and gmake on BSD
+
# $MAKE在Linux上是make,在BSD上是gmak
# /path/to/ can be omitted when ppc386 (32 bit) or ppcx64 (64 bit) is in the path
+
# /path/to/可以被忽略,当ppc386 (32位)或ppcx64 (64位)在path中时
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Install FPC. Again in work/fpc, run
+
* 安装FPC。在工作的/fpc中,运行
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$MAKE install FPC=compiler/ppcx64 PREFIX=$THEPREFIX
 
$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
+
#如果不在Intel x86上,使用相关的编译器替换FPC=compiler/ppcx64 (或者针对32位的ppc386)
#THEPREFIX= usually is /usr/local or just /usr, but eg on NetBSD it is /usr/pkg for ports)
+
#THEPREFIX= 通常是/usr/local或只是/usr,但是在NetBSD上,它是/usr/pkg)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Create a symlink:
+
* 创建符号链接:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 218: Line 220:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Install sources:
+
* 安装源文件:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 224: Line 226:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Create a symlink for default FPC source path:
+
* 为默认FPC源文件路径创建一个符号链接:
  
 
<syntaxhighlight lang=bash>
 
<syntaxhighlight lang=bash>
Line 230: Line 232:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Set up fpc.cfg configuration file:
+
* 设置fpc.cfg配置文件:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 236: Line 238:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* Optionally test to see if <code>ppcx64 -i</code> (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 <code>ppcx64 -viwn</code>, and see if that gives errors.
+
* 可选测试,来查看是否<code>ppcx64 -i</code> (或者你的架构使用的任何编译器)给出输出,否则将给出一个用户需要添加$PREFIX/bin到当前path 的警告。尝试使用<code>ppcx64 -viwn</code>,来编译一个程序,并查看它是否会给出错误。
  
 
Notes:
 
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 <syntaxhighlight lang="bash">find . >ll</syntaxhighlight>
+
* 如果你需要fpcmake软件包列表,你需要自己生成或提供,(在port中,或者在一个额外的归档文件中),不管哪种方法,做一次模拟安装到/tmp/pack中,并使用下面的目录来确认文件是否已经安装
 +
<syntaxhighlight lang="bash">find . >ll</syntaxhighlight>
  
* $THEPREFIX and $ETCDIR should be user configurable. Otherwise local installs aren't possible.
+
* $THEPREFIX和$ETCDIR应该是用户可配置的。否则本地安装是不可能的。
  
* BSDHIER=1 on all make commands forces BSD hierarchy conventions.
+
* BSDHIER=1在所有BSD系统上的make命令。
  
 
== Windows ==
 
== Windows ==
Line 250: Line 253:
 
===  安装FPC二进制文件 ===
 
===  安装FPC二进制文件 ===
 
   
 
   
到目前为止,获取一个可以工作的Free Pascal安装的最简单的方法是,从[https://sourceforge.net/projects/freepascal/files/Win32/3.2.0/ SourceForge存储库]现在当前的二进制发布版本 - 发布版本包含当前的Free Pascal编译器和Free Pascal 库。
+
到目前为止,获取一个可以工作的Free Pascal安装的最简单的方法是,从[https://sourceforge.net/projects/freepascal/files/Win32/3.2.0/ SourceForge存储库]下载当前的二进制发布版本 - 发布版本包含当前的Free Pascal编译器和Free Pascal 库。
  
=== Installing from source on Windows ===
+
=== 在Windows上从源文件安装 ===
  
Installing from the sources -- see the next section to know how to get them -- is not for novices, since you need a starting compiler as well.
+
从源文件安装 -- 查看接下来的章节来了解如何获取源文件 -- 这不是针对新手的,因为你也需要一个最开始的编译器。
  
'''FPC Sources'''
+
'''FPC源文件'''
  
<<<< See section above under [[#FPC_sources|FPC Sources]] for Linux, where the use of SVN is described >>>>
+
<<<< 查看上述针对Linux的[#FPC_sources|FPC源文件]]的章节,在其中描述了SVN的使用 >>>>
  
The easiest way to get the Free Pascal sources is via SVN; see the next section for more on that. You can also download the package as a whole -- see https://www.freepascal.org/develop.html for the daily snapshot of the release tree.
+
通过SVN获取Free Pascal源文件是最简单的方法;更多信息查看下一章节。你也可以下载一个整个软件包 -- 发布树的每日快照版本查看 https://www.freepascal.org/develop.html
  
'''FPC Sources via SVN'''
+
'''通过SVN获取FPC源文件'''
  
You will need to have a SVN client such as TortoiseSVN installed in order to perform the steps below. The exact commands vary between SVN clients; the ones given below are for the command line Subversion client downloadable from  https://sourceforge.net/projects/win32svn/.
+
为了执行上述步骤,你将需要安装一个SVN客户端,例如TortoiseSVN。在不同SVN客户端之间的命令名 称各不相同;下面给出的是针对命令行的Subversion客户端,可以从https://sourceforge.net/projects/win32svn/下载。
  
First create a directory in which you'd like to put the sources. Any normal user can do this. Create a directory for FPC (e.g. C:\Source), then do the following at the command prompt:
+
首先在你想放置源文件的目录中创建一个目录。任何普通用户都可以这样做。为FPC创建一个目录(例如,C:\Source)然后,在命令提示符中执行下面的命令:
  
 
<syntaxhighlight lang="bash">C:\Source> svn checkout https://svn.freepascal.org/svn/fpc/trunk fpc</syntaxhighlight>
 
<syntaxhighlight lang="bash">C:\Source> svn checkout https://svn.freepascal.org/svn/fpc/trunk fpc</syntaxhighlight>
Hint: To download/update the latest changes you can simply do
+
提示:为下载/更新最新的更改,你可以简单地执行:
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
 
C:\> cd Source\FPC
 
C:\> cd Source\FPC
Line 275: Line 278:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
See: https://www.freepascal.org/down/i386/win32.html. 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.
+
查看: https://www.freepascal.org/down/i386/win32.html。下载发行软件包(fpc-3.2.0.i386-win32.exe)并运行它 - 它是一个自解压安装器,因此只需要遵循安装说明来安装它。安装器应该会按情况设置PATH环境变量。
  
Then restart windows.
+
接下来重新启动windows。
  
After you have FPC binaries installed you can build FPC source from subversion.  
+
在你安装FPC二进制文件后,你可以从中构建FPC源文件。  
  
Hints:   
+
提示:   
  
* 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".
+
* Windows (7+) 要求使用一个提升权限状态的用户命令提示符。从开始菜单中右键单击"命令提示符",并选择"以管理员身份运行"
* 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).
+
* YOUR-PREFIX完全取决于你安装FPC的位置。在撰写本文时,二进制文件被指示使用一 个"C:\FPC" 的默认位置,并且将它们被放置到"C:\FPC\3.2.0"中。在Linux下, make install脚本将被调整为创建一个新是子文件夹,如果自上次构建后FPC发生更改的话。在Windows下的脚本将不会做这些。因此,如果你知道子文 件夹的名称,例如 3.1.1,吗可以具体指定它。但是,因为版本经常更改,建议你只选择和维护一个前缀,而不考虑FPC版本。一个很好的前缀的C:\FPC,但是你必需确 保C:\FPC\bin \i386-win32\已经添加到你的path环境变量中(查看上面如何设置你的path,并将其从二进制文件版本更改为新编译的二进制文件版本)
  
Instructions:
+
操作指南:
  
* In command Prompt navigate to the localized FPC source. ie.) type "cd c:\Developer\FPC"
+
* 在命令提示符中导航到本地的FPC源文件。例如,输入"cd c:\Developer\FPC"
* To build FPC type "make all"
+
* 为构建FPC,输入"make all"
* To overwrite existing FPC type "make install PREFIX=YOUR-PREFIX"
+
* 为重写已存在的FPC,输入"make install PREFIX=YOUR-PREFIX"
* To install source type "make install sourceinstall PREFIX=YOUR-PREFIX"
+
* 为安装源文件,输入"make install sourceinstall PREFIX=YOUR-PREFIX"
  
'''Compiling/installing FPC from sources with SVN (Win32)'''
+
'''使用SVN (Win32)从源文件编译/安装FPC'''
  
Version FPC '''3.2.0''' or '''trunk'''
+
FPC '''3.2.0'''版本 或 '''trunk'''版本
  
''STEP #1: Create directories and get the sources''
+
''步骤#1: 创建目录和获取源文件''
  
Create the following directories:
+
创建下面的目录:
 
   c:\freepascal\
 
   c:\freepascal\
 
   c:\freepascal\binutils\
 
   c:\freepascal\binutils\
Line 306: Line 309:
 
   c:\freepascal\fpc\3.2.0\
 
   c:\freepascal\fpc\3.2.0\
  
or for fpc trunk:
+
或对于fpc trunk版本来说:
 
   c:\freepascal\
 
   c:\freepascal\
 
   c:\freepascal\binutils\
 
   c:\freepascal\binutils\
Line 313: Line 316:
 
   c:\freepascal\fpc\trunk\
 
   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\
+
你将需要最新的'''发布版本'''编译器来构建一个新的编译器。使用FTP(下面的地址)来获取ppc386(编译器),并解压缩它到c:\freepascal\binutils\
  
 
   ftp://ftp.freepascal.org/pub/fpc/dist/3.2.0/bootstrap/i386-win32-ppc386.zip
 
   ftp://ftp.freepascal.org/pub/fpc/dist/3.2.0/bootstrap/i386-win32-ppc386.zip
  
After installing [http://tortoisesvn.tigris.org/ TortoiseSVN], download the sources from SVN using a URL for each directory, see:
+
在安装[http://tortoisesvn.tigris.org/ TortoiseSVN]后,使用针对每个目录的URL来从SVN中下载源文件,查看:
  
 
   Dir: c:\freepascal\binutils\i386-win32\
 
   Dir: c:\freepascal\binutils\i386-win32\
 
   URL: https://svn.freepascal.org/svn/fpcbuild/branches/fixes_3_0/install/binw32
 
   URL: https://svn.freepascal.org/svn/fpcbuild/branches/fixes_3_0/install/binw32
  
or for fpc trunk:
+
或对于fpc trunk版本来说:
  
 
   Dir: c:\freepascal\binutils\i386-win32\
 
   Dir: c:\freepascal\binutils\i386-win32\
Line 330: Line 333:
 
   URL: https://svn.freepascal.org/svn/fpc/branches/fixes_3_0/
 
   URL: https://svn.freepascal.org/svn/fpc/branches/fixes_3_0/
  
or for fpc trunk:
+
或对于fpc trunk版本来说:
  
 
   Dir: c:\freepascal\fpc\trunk
 
   Dir: c:\freepascal\fpc\trunk
 
   URL: https://svn.freepascal.org/svn/fpc/trunk/
 
   URL: https://svn.freepascal.org/svn/fpc/trunk/
  
''STEP #2: Create a BAT file to compile FPC''
+
''步骤 #2: 创建一个BAT文件来编译FPC''
  
After everything is downloaded, we need a BAT file to compile the FPC sources.
+
在下载完所有的东西后,我们需要一个BAT文件来编译FPC源文件。
Create a new file c:\freepascal\makefpc.bat and copy/paste the following script:
+
创建一个新的文件c:\freepascal\makefpc.bat,并复制/粘贴下面的脚本:
  
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
Line 355: Line 358:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
or for FPC trunk:
+
或对于fpc trunk版本来说:
  
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
Line 373: Line 376:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
For crosscompiler to x86_64 add the following after the first make:
+
对于针对x86_64的交叉编译器,在第一个make后添加下面的内容:
  
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
Line 380: Line 383:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
''STEP #3: Make and install FPC''
+
''步骤 #3: Make和安装FPC''
  
At the prompt (cmd.exe), navigate to the directory c:\freepascal and execute the script we just wrote:  
+
在命令提示符中(cmd.exe),导航到目录c:\freepascal and execute the script we just wrote:  
  
 
<syntaxhighlight lang="dos">
 
<syntaxhighlight lang="dos">
Line 389: Line 392:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Done!
+
完成!
  
 
== macOS ==
 
== macOS ==
  
{{Warning|If you are intending to also install Lazarus, please ignore these instructions and instead refer to [[Installing Lazarus on macOS]].}}
+
{{Warning|如果你也打算安装Lazarus,请忽略这些操作指南,而参考[[Installing Lazarus on macOS |在macOS上安装Lazarus]]}}
  
=== Step 1: Download Xcode ===  
+
=== 步骤1:下载Xcode ===  
  
You need the Apple Developer tools, which are a part of the Xcode development environment.
+
你需要Apple开发人员工具,它们是Xcode开发环境的一部分。
  
 
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>.
 
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>.
  
Older systems:
+
较旧的系统:
  
 
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) -
 
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) -
Line 408: Line 411:
 
sudo xcode-select -s /Developer/Xcode.app/Contents/Developer </syntaxhighlight>
 
sudo xcode-select -s /Developer/Xcode.app/Contents/Developer </syntaxhighlight>
  
=== Step 2: Xcode Command Line Tools ===
+
=== 步骤2: Xcode命令行工具 ===
  
 
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)-
 
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)-
Line 417: Line 420:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Step 3: Download FPC ===
+
=== 步骤3:下载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.
+
[https://www.freepascal.org/download.html Free Pascal网站]现在Free Pascal Compiler (FPC)和FPC源文件。当你到达下载页面时,请选择一个镜像网站,然后为你的操作系统选择正确的版本
  
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.
+
这些二进制安装工具包由FPC开发人员构建和跟踪正式发布。因为这些安装包没有代码签名,也没有经过苹果的认证,因此,你需要在安装软件包上单击并选择"打开",或者在安装软件包上右击并在弹出的菜单中选择"打开",接下来确认你要从未知开发人员安装。
  
== Other macOS installation options ==
+
== 其它的macOS安装选项 ==
  
 
=== fpcupdeluxe ===
 
=== fpcupdeluxe ===
  
You could also consider using [[fpcupdeluxe]] to install FPC.
+
你也可以考虑使用[[fpcupdeluxe]]来安装FPC。
  
=== fink & MacPorts===
+
=== fink和MacPorts===
  
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.
+
或者,你可以使用macOS的一个软件包(像[http://finkproject.org/ fink][https://www.macports.org MacPorts]来安装FPC。她们附加的好处是容易安装和移除FPC,以及大量的其它的开放源文件的软件软件包。Fink也为很多CPU和操作系统提供很多[[Cross_compiling#From_macOS_to_any_using_fink | Free Pascal交叉编译器]]
  
== Testing the FPC Install ==
+
== 测试FPC安装 ==
  
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 <tt>helloworld.pas</tt>:
+
在这个阶段,你可能想尝试一个简单而快速的FPC测试。从命令行中(Mac - 打开一个应用程序 > 实用程序 > 终端),复制这个非常短的程序,并保存它为文件<tt>helloworld.pas</tt>
  
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
Line 444: Line 447:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now compile this simple code with this command line:
+
现在使用这个命令行编译这个简单的代码:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 450: Line 453:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
It should very quickly make an executable called, you guessed it, "helloworld". Run this executable with this command:
+
它应该会快速生成一个可执行文件,你可能会猜到它的名称为"helloworld"。使用这个命令来运行这个可执行文件:
 
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
./helloworld <enter>
 
./helloworld <enter>
 
</syntaxhighlight>
 
</syntaxhighlight>
  
If that worked, well done!
+
如果这样工作,很好地完成了!
  
 
== 安装交叉编译器 ==
 
== 安装交叉编译器 ==

Latest revision as of 01:49, 1 June 2021

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

这里有一个如何安装和构建FreePascal编译器的广泛讨论,网址:http://www.stack.nl/~marcov/buildfaq.pdf - 对于一些用户来说,它可能有点太过于详细了,但是它是非常全面的。

概述

这里有很多方法来在你的系统上安装FPC。当前发布版本,trunk版本,有时beta版本和RC版本也可以从FPC网站https://sourceforge.net/projects/freepascal/files/ (tar, exe, rpm, dmg 文件)直接获得。另外,从Lazarus的下载网站中也提供了FPC的版本(包括rpm和deb文件),Lazarus网址http://sourceforge.net/projects/lazarus/files/。 Linux用户差不多都能从Linux发行版的存储库中找到FPC,但是可能会发现FPC是过时的版本。

从源文件构建FPC也是可能的,通常每个发布版本都可以使用先前的发布版本构建。在系统安装应用程序空间中(通常需root几或administrator访问权限)或在你自己的用户控件中安装FPC都是能做到的。这些取决于您的特定的操作系统环境。

Linux

FPC二进制文件软件包

尽管最新的FPC3.2.0已经发布,但是只有少数发行版的存储库中存在新的FPC编译器。你可以做一个FPC -

  • 如果你使用rpm软件包,你可以在https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/中找到FPC320,或者在https://www.freepascal.org/download.html中的更大范围内查找,你可以使用一个命令来安装,像 -
yum localinstall fpc-3.2.0-1.x86_64.rpm
// 或者
rpm -Uvh fpc-3.2.0-1.x86_64.rpm
  • 如果你使用deb软件包,尝试一个可用的软件包,但是它并不是与Lazarus(https://sourceforge.net/projects/lazarus/files/) 绑定在一起。使用gdebi安装,也或者这个命令(注意在文件名称前面的./ ,如果你不使用一个精确的路径到文件名称,apt将搜索它自己的官方存储库,而不是你想要的)-
apt install ./fpc-laz_3.2.0-1_amd64.deb

FPC的Tar包

另一个选项是从一个tar包安装,一种简单并且可能更有用的模型。这些tar包可广泛地用于类Unix系统中。你需要为你的操作系统和CPU来下载恰当的二进制文件tar包,并且你也可能需要所有操作系统/CPU都通用的源文件 文件。你可以在你自己的空间中安装FPC,而不是作为root用户。

这里有一系列的命令,而不是一个脚本,这些命令将在一个64位Linux系统上安装FPC。这些命令可以编写成脚本,但是需要健全性和错误检查。注意,我喜欢在我的$HOME/bin中安装像这样的大小,如果你喜欢在$HOME中安装东西,甚至会更简单一些,我确信你可以看到其中的不同点。

Light bulb  Note: 一 次tar包安装不会解决依赖关系,如果这些依赖还不存在,首先安装binutils, make, gcc。
cd
mkdir -p bin/FPC/Tars
mkdir bin/FPC/SRC
cd bin/FPC/Tars
# 下载源文件和编译器tar包,为不同的CPU(或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
# 当询问在何处安装时,输入$HOME/bin/FPC/fpc-3.2.0 ,并在此之后接受所有的默认值。

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

# 在.bashrc的结尾处,添加并设置一个编译器在哪里的路径,如果你不使用bash,相应地调整! 
echo "PATH=\"\$HOME/bin/FPC/fpc-3.2.0/bin\":\"\$PATH\"" >> ~/.bashrc
source ~/.bashrc

# 不重要的测试
cd 
fpc -iV

Light bulb  Note: 上面第二个的wget假设你正在使用的是一个amd64 (AMD或Intel)类型的机器,其它的平台需要一个不同的tar包。例如,针对一个Raspberry Pi,你可以使用:-

wget https://sourceforge.net/projects/freepascal/files/Linux/3.2.0/fpc-3.2.0.arm-linux.tar
这个tar包拥有armhf的32位编译器。顺便说一句,Raspberry Pi可能需要你增加swap空间到至少1G。如果你计划稍后使用FPC构建一些大型应用程序的话。

FPC源文件

FPC源文件文件存储在一个Subversion (SVN)存储库中,该存储库保持跟踪源文件树的所有更改。在你拥有源文件后,关于如何安装它们是说明,请查看在 BSD/Linux下从源文件安装

使用SVN从源文件存储库更新

SVN存储库已经为每个人提供了只读可访问权限。这意味你可以直接访问代码,并且你将获得最新的源文件。这是一个方法,它需要较少的宽带,在你完成第一次下载后(在SVN中签出)。

获取源文件

首先,你需要一个已经安装的SVN客户端。使用你的软件包管理器,安装一个工具,像在Windows上的TortoiseSVN ,更多信息查看网页

使用命令行SVN:更改目录(cd)到你开发区域的父目录,例如,为了首次在你的home目录下的一个fpc子目录下,索回完整的源文件存储库,输入:

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

为更新上面已下载(已签出的)的源文件:

cd ~
svn update fpc

获取一个单独的分支

如果当前的trunk版本处于一个快速变化的状态,不适合多用。除非你想在编译器本身上工作,你可以停留在一个带有fixes分支的更新版本上。为此,你必需找到一个你想要跟踪的稳定分支,而不是默认的trunk开发版本。

下面的示例向你展示如何跟踪fixes_3_2版本;当然,可根据你想跟踪的的分支来进行替换。 Th这个示例将在你的home目录下的另外一个目录下保留fixes分支 - 在一个目录中放置源文件的两个版本是没有意义的...

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

照例更新:

cd ~
svn update fpc_fixes_3_2

文档源文件

文档源文件位于一个名称为fpcdocs的单独的存储库中,因此获取它们的命令是:

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

如果你想要学习更多关于subversion的知识,阅读这本极好的Subversion书籍,它也可以在网上以不同的格式免费获取。

更多信息,查看Free Pascal网站

FreeBSD

Light bulb  Note: 如果你也希望安装Lazarus,你可以忽略下面安装FPC的步骤,因为Lazarus的port集合将为你 安装FPC

从port集合安装

FreeBSD的port集合在/usr/ports/lang/fpc中有FPC v3.0.4版本。FPC 分散在38 (!)软件包中。FPC源文件现在已经默认安装了;它以前需要从/usr/ports/distfiles/freepascal中复制和解压缩。

这必需以root的身份来完成。

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

在安装FPC后,你只需要以一个普通用户的身份来检查它是否工作,运行:

$ fpc test

这应该会产生一个类似于这样的输出:

 Free Pascal Compiler version 3.0.4 [2020/06/14] for x86_64
 Copyright (c) 1993-2017 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

从tar包安装

根据你的系统选择恰当的32位/64位的tar包文件。对于x86_64的64位的FreeBSD,从x86_64下 载。对于i386的32位的FreeBSD,从i386下载。

为安装Free Pascal,从一个终端中运行:

$ 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-$FPC_VERSION.$PLATFORM-freebsd11.tar
$ cd fpc-3.2.0.x86_64-freebsd
$ sh install.sh

根据需要替换Free Pascal版本(3.0.4, 3.2.0或3.3.1) 和架构(X86_64或i386)。

如果你想全局安装Free Pascal Compiler,例如在/usr/local中,作为 root用户身份运行install.sh脚本。

如果你在FreeBSD 12或更新的版本,默认的链接器是lld。这可能会导致问 题,例如,如果你的代码使用 cthreads单元,像下面的程序一样:

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

为这个程序生成的可执行文件在运行时将导致一个分段错误。为修复这个问题,你需要安装GNU的链接器:

root# pkg install binutils

并确保/usr/local/bin/存在于你的PATH环境变量中,并在/tt>/usr/bin/之前

在BSD/Linux上从源文件安装

实际上,你需要:

1. 一个包含所有FPC源文件的文件(https://sourceforge.net/projects/freepascal/files/Source/3.2.0/fpc-3.2.0.source.tar.gz).

2. 一个启动(自举)FPC编译器。一个FPC发布版本总是可以由先前发布的FPC版本所构建,FPC trunk版本也总是可以由当前的FPC发布版本所构建。你可以现在一个自举Free Pascal编译器或者使用你发行版的软件包管理器/软件系统来安装一个编译器。

FPC构建过程:

  • 获取编译的文件(启动编译器),FPC源文件文件或源文件svn目录
  • 如果使用FPC源文件文件:在工作中提取/解压缩文件
  • 构建:进入工作的/fpc/目录中并运行:
# Linux使用
export MAKE=`which make` ; echo $MAKE 
# FreeBSD使用(默认csh,或tcsh):
set MAKE=`which gmake` ; echo $MAKE
# FreeBSD使用(bash):
export MAKE=`which gmake` ; echo $MAKE
$MAKE all OPT='-gl' FPC=/path/to/startingcompiler-name-ppcx64
# $MAKE在Linux上是make,在BSD上是gmak
# /path/to/可以被忽略,当ppc386 (32位)或ppcx64 (64位)在path中时
  • 安装FPC。在工作的/fpc中,运行
$MAKE install FPC=compiler/ppcx64 PREFIX=$THEPREFIX
#如果不在Intel x86上,使用相关的编译器替换FPC=compiler/ppcx64 (或者针对32位的ppc386)
#THEPREFIX= 通常是/usr/local或只是/usr,但是在NetBSD上,它是/usr/pkg)
  • 创建符号链接:
ln -s $THEPREFIX/lib/fpc/3.2.0/ppcx64 $THEPREFIX/bin/ppcx64
  • 安装源文件:
$MAKE install sourceinstall PREFIX=$THEPREFIX
  • 为默认FPC源文件路径创建一个符号链接:
ln -sf $THEPREFIX/share/src/3.2.0/fpc /usr/share/fpcsrc
  • 设置fpc.cfg配置文件:
$THEPREFIX/lib/fpc/3.2.0/samplecfg $THEPREFIX/lib/fpc/3.2.0 $ETCDIR
  • 可选测试,来查看是否ppcx64 -i (或者你的架构使用的任何编译器)给出输出,否则将给出一个用户需要添加$PREFIX/bin到当前path 的警告。尝试使用ppcx64 -viwn,来编译一个程序,并查看它是否会给出错误。

Notes:

  • 如果你需要fpcmake软件包列表,你需要自己生成或提供,(在port中,或者在一个额外的归档文件中),不管哪种方法,做一次模拟安装到/tmp/pack中,并使用下面的目录来确认文件是否已经安装
find . >ll
  • $THEPREFIX和$ETCDIR应该是用户可配置的。否则本地安装是不可能的。
  • BSDHIER=1在所有BSD系统上的make命令。

Windows

安装FPC二进制文件

到目前为止,获取一个可以工作的Free Pascal安装的最简单的方法是,从SourceForge存储库下载当前的二进制发布版本 - 发布版本包含当前的Free Pascal编译器和Free Pascal 库。

在Windows上从源文件安装

从源文件安装 -- 查看接下来的章节来了解如何获取源文件 -- 这不是针对新手的,因为你也需要一个最开始的编译器。

FPC源文件

<<<< 查看上述针对Linux的[#FPC_sources|FPC源文件]]的章节,在其中描述了SVN的使用 >>>>

通过SVN获取Free Pascal源文件是最简单的方法;更多信息查看下一章节。你也可以下载一个整个软件包 -- 发布树的每日快照版本查看 https://www.freepascal.org/develop.html

通过SVN获取FPC源文件

为了执行上述步骤,你将需要安装一个SVN客户端,例如TortoiseSVN。在不同SVN客户端之间的命令名 称各不相同;下面给出的是针对命令行的Subversion客户端,可以从https://sourceforge.net/projects/win32svn/下载。

首先在你想放置源文件的目录中创建一个目录。任何普通用户都可以这样做。为FPC创建一个目录(例如,C:\Source)然后,在命令提示符中执行下面的命令:

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

提示:为下载/更新最新的更改,你可以简单地执行:

C:\> cd Source\FPC
C:\Source\FPC> svn update

查看: https://www.freepascal.org/down/i386/win32.html。下载发行软件包(fpc-3.2.0.i386-win32.exe)并运行它 - 它是一个自解压安装器,因此只需要遵循安装说明来安装它。安装器应该会按情况设置PATH环境变量。

接下来重新启动windows。

在你安装FPC二进制文件后,你可以从中构建FPC源文件。

提示:

  • Windows (7+) 要求使用一个提升权限状态的用户命令提示符。从开始菜单中右键单击"命令提示符",并选择"以管理员身份运行"。
  • YOUR-PREFIX完全取决于你安装FPC的位置。在撰写本文时,二进制文件被指示使用一 个"C:\FPC" 的默认位置,并且将它们被放置到"C:\FPC\3.2.0"中。在Linux下, make install脚本将被调整为创建一个新是子文件夹,如果自上次构建后FPC发生更改的话。在Windows下的脚本将不会做这些。因此,如果你知道子文 件夹的名称,例如 3.1.1,吗可以具体指定它。但是,因为版本经常更改,建议你只选择和维护一个前缀,而不考虑FPC版本。一个很好的前缀的C:\FPC,但是你必需确 保C:\FPC\bin \i386-win32\已经添加到你的path环境变量中(查看上面如何设置你的path,并将其从二进制文件版本更改为新编译的二进制文件版本)。

操作指南:

  • 在命令提示符中导航到本地的FPC源文件。例如,输入"cd c:\Developer\FPC"
  • 为构建FPC,输入"make all"
  • 为重写已存在的FPC,输入"make install PREFIX=YOUR-PREFIX"
  • 为安装源文件,输入"make install sourceinstall PREFIX=YOUR-PREFIX"

使用SVN (Win32)从源文件编译/安装FPC

FPC 3.2.0版本 或 trunk版本

步骤#1: 创建目录和获取源文件

创建下面的目录:

 c:\freepascal\
 c:\freepascal\binutils\
 c:\freepascal\binutils\i386-win32\
 c:\freepascal\fpc\
 c:\freepascal\fpc\3.2.0\

或对于fpc trunk版本来说:

 c:\freepascal\
 c:\freepascal\binutils\
 c:\freepascal\binutils\i386-win32\
 c:\freepascal\fpc\
 c:\freepascal\fpc\trunk\

你将需要最新的发布版本编译器来构建一个新的编译器。使用FTP(下面的地址)来获取ppc386(编译器),并解压缩它到c:\freepascal\binutils\

 ftp://ftp.freepascal.org/pub/fpc/dist/3.2.0/bootstrap/i386-win32-ppc386.zip

在安装TortoiseSVN后,使用针对每个目录的URL来从SVN中下载源文件,查看:

 Dir: c:\freepascal\binutils\i386-win32\
 URL: https://svn.freepascal.org/svn/fpcbuild/branches/fixes_3_0/install/binw32

或对于fpc trunk版本来说:

 Dir: c:\freepascal\binutils\i386-win32\
 URL: https://svn.freepascal.org/svn/fpcbuild/trunk/install/binw32
 Dir: c:\freepascal\fpc\3.0.4
 URL: https://svn.freepascal.org/svn/fpc/branches/fixes_3_0/

或对于fpc trunk版本来说:

 Dir: c:\freepascal\fpc\trunk
 URL: https://svn.freepascal.org/svn/fpc/trunk/

步骤 #2: 创建一个BAT文件来编译FPC

在下载完所有的东西后,我们需要一个BAT文件来编译FPC源文件。 创建一个新的文件c:\freepascal\makefpc.bat,并复制/粘贴下面的脚本:

@echo on
set myroot=c:\freepascal
set myFPC=%myroot%\fpc\3.2.0 
set mybinutils=%myroot%\binutils
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
fpcmkcfg -d basepath=%myFPC% -o .\fpc.cfg 
copy fpc.exe %mybinutils%\i386-win32

或对于fpc trunk版本来说:

@echo on
set myroot=c:\freepascal
set myFPC=%myroot%\fpc\trunk 
set mybinutils=%myroot%\binutils
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

对于针对x86_64的交叉编译器,在第一个make后添加下面的内容:

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

步骤 #3: Make和安装FPC

在命令提示符中(cmd.exe),导航到目录c:\freepascal and execute the script we just wrote:

cd /d c:\freepascal
makefpc.bat

完成!

macOS

Warning-icon.png

Warning: 如果你也打算安装Lazarus,请忽略这些操作指南,而参考在macOS上安装Lazarus

步骤1:下载Xcode

你需要Apple开发人员工具,它们是Xcode开发环境的一部分。

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.

较旧的系统:

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

步骤2: Xcode命令行工具

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

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

步骤3:下载FPC

Free Pascal网站现在Free Pascal Compiler (FPC)和FPC源文件。当你到达下载页面时,请选择一个镜像网站,然后为你的操作系统选择正确的版本

这些二进制安装工具包由FPC开发人员构建和跟踪正式发布。因为这些安装包没有代码签名,也没有经过苹果的认证,因此,你需要在安装软件包上单击并选择"打开",或者在安装软件包上右击并在弹出的菜单中选择"打开",接下来确认你要从未知开发人员安装。

其它的macOS安装选项

fpcupdeluxe

你也可以考虑使用fpcupdeluxe来安装FPC。

fink和MacPorts

或者,你可以使用macOS的一个软件包(像finkMacPorts来安装FPC。她们附加的好处是容易安装和移除FPC,以及大量的其它的开放源文件的软件软件包。Fink也为很多CPU和操作系统提供很多 Free Pascal交叉编译器

测试FPC安装

在这个阶段,你可能想尝试一个简单而快速的FPC测试。从命令行中(Mac - 打开一个应用程序 > 实用程序 > 终端),复制这个非常短的程序,并保存它为文件helloworld.pas

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

现在使用这个命令行编译这个简单的代码:

fpc helloworld.pas <enter>

它应该会快速生成一个可执行文件,你可能会猜到它的名称为"helloworld"。使用这个命令来运行这个可执行文件:

./helloworld <enter>

如果这样工作,很好地完成了!

安装交叉编译器

一个交叉编译器允许你为一个平台创建一个不同于正在使用的编译平台的二进制文件(可执行文件)。例如,在macOS下工作,并为Win32,FreeBSD或Linux创建可执行文件。 关于如何安装交叉编译器的详细情况,查看交叉编译

请参阅