In this chapter, we will begin learning about the Lazarus IDE for Free Pascal by installing and configuring Lazarus. We will learn the following:
Why use Lazarus
How to install Lazarus on a Linux platform
How to install Lazarus on a Windows platform
How to install Lazarus on Mac OS
How to install Lazarus on FreeBSD
How to create a basic configuration for Lazarus
Lazarus is an open source, cross-platform integrated development environment (IDE) for the open source Pascal compiler, Free Pascal (FPC). For the purpose of this book, it is to be assumed that when we say Lazarus, we are talking about Lazarus in conjunction with Free Pascal. Free Pascal offers a high degree of compatibility with Delphi's Object Pascal language, which includes many of the same libraries. The Lazarus Component Library (LCL) is, in many cases, equivalent to Delphi's VCL, including versions of many of the same controls used to create applications that have a graphical user interface. Just as with Delphi, Lazarus can also be used to create console applications, dynamic link libraries, or web applications.
With all the given similarities to Delphi, it is quite obvious that Lazarus along with Free Pascal can make a suitable open source replacement for Delphi. But, Lazarus is not limited to this. Lazarus can be used to develop Free Pascal applications that can be compiled and run on Linux-based smartphones. It is also possible to develop web applications with Lazarus using additional packages, such as Fpweb, FreeSpider, and Raudus. Compiled libraries can be created, which can be accessed by other programming languages, such as Python or C++.
Lazarus' greatest advantage is that it allows programmers to create cross-platform applications. Lazarus' technique for creating cross-platform applications is referred to as write once compile anywhere. This alludes to the fact that you can write applications on one platform, such as Linux, and compile it on different platforms, such as Apple's OS X or Microsoft's Windows operating systems. Currently, Lazarus supports Windows, WinCE, Mac OS X, iOS, Linux, and Android operating systems. In this book, we will focus on Linux and Windows as these are the largest current user bases in the Lazarus community.
The Lazarus IDE is available as binary packages for Linux in the Red Hat Package Management (RPM) format, Debian (DEB) format, or in tar gzip format. These packages are available for 32-bit or 64-bit distributions of Linux. Certain distributions of Linux, such as Ubuntu, make Lazarus available through their custom package managers. For information on installing Lazarus using such package management software, check the instructions available from the distribution's website or manuals.
The Lazarus binary
RPM package is available from the Lazarus SourceForge.net (http://sourceforge.net/projects/lazarus/files/) download area. Once you have accessed this page, choose the correct link for your platform package, in this case either
Lazarus Linux x86_64 RPM for 64-bit platforms or
Lazarus Linux i386 RPM for 32-bit platforms. We will be using the 32-bit package for this example. After clicking on the correct link, choose the current release link, in this case
Lazarus 1.0.2. Once you are in this area, all the packages needed to install Lazarus are available to be downloaded. Download the following packages:
Also available is the optional package,
fpc-debuginfo-2.6.0-0.laz.i686.rpm, which provides debug information for the system units. This is only needed if you want to do development for Free Pascal itself, which is beyond the scope of this book.
GNU as the GNU assembler
GNU Id or the GNU linker
GTK+ 2.x or Qt: Most Linux distributions already install GTK+ 2.x. You can also download the libraries from http://www.gtk.org. Qt is also supported by most distributions and is installed together with KDE.
To begin the installation of Lazarus, log into your system as a root user. First install the Free Pascal for the Lazarus package containing the following command:
# rpm -UvH fpc-2.6.0-0.laz.i686.rpm
After the successful completion of this package, next we will need to install the Free Pascal source code package. The Free Pascal source code package is required to operate certain functions in Lazarus. If the IDE cannot find the Free Pascal source, the user will be presented with a warning box with the following message:
The Free Pascal source was not found. Some functions will not work.
To install the Free Pascal source, use the following command:
# rpm -UvH fpc-src-2.6.0-0.laz.i686.rpm
After the successful completion of the installation of the Free Pascal source, all that is left to do is to install the Lazarus IDE itself with the following command:
# rpm -UvH Lazarus-1.0-1.i386.rpm
With the successful completion of these three packages, you are ready to use the Lazarus IDE. Under the GNOME desktop, Lazarus can be accessed from the Applications menu under the Programming submenu.
For Debian-based Linux distributions, the SourceForge.net Lazarus repository contains Debian packages for 32-bit and 64-bit distributions. Access the SourceForge.net repository at http://sourceforge.net/projects/lazarus/files/. For 32-bit Debian-based distributions, choose the
Lazarus Linux i386 DEB subfolder. For 64-bit Debian-based distributions, choose the
Lazarus Linux amd64 DEB subfolder. Next, choose the current Lazarus release, which at the time of writing is
Lazarus 1.0.2. Download all the Debian packages within this folder.
For 32-bit systems:
For 64-bit systems:
Once the packages are downloaded, install them using the following command:
dpkg -i <package_name>
Install each of the packages for Free Pascal, Free Pascal Source, and the Lazarus IDE.
There is an Ubuntu repository available at http://www.hu.freepascal.org that contains Lazarus and FPC debs. This repository can be used with
apt-get. Before using this repository with
apt-get, it first needs to be added to the apt.
First, we need to add the repository's
gpg key to the
apt keys with the following commands as a root user:
# gpg –keyserver hkp://pgp.mit.edu:11371 –recv-keys 6A11800F # gpg -a –export 6A11800F | apt-key add -
deb http://www.hu.freepascal.org/lazarus/lazarus-stable universe
Once the repository is added to the list of available repositories, Lazarus can be installed with the following commands, again as root:
# apt-get update # apt-get install lazarus
The Lazarus and Free Pascal binary packages for the Windows operating systems are available from the SourceForge.net repository at http://sourceforge.net/projects/lazarus/files/. The Windows installer packages include both Free Pascal and Lazarus in an easy-to-install package. Choose either the
Lazarus Windows 32 bits or
Lazarus Widows 64 bits subfolder depending on your OS version. Next choose the current version of the Lazarus subfolder, which at the time of writing is
Lazarus 1.02. Click on the
lazarus-1.0.2-fpc-2.6.0-win32.exe Windows installer package. For Windows 32-bit operating systems or for Windows 64-bit operating systems, click on
If you intend to develop applications for WinCE using Lazarus, you will need to download the WinCE installer package, that is,
lazarus-1.0.2-fpc-2.6.0-cross-arm-wince-win32.exe. There is no 64-bit version available.
Once you have the files downloaded, double-click on the executable file to start the installation process. The installation process, as with most Windows installers, is straightforward. Unless you have a need to change the defaults, just click Next through the installation wizard's dialogs. One dialog to note is the Select Components dialog (shown in the following screenshot), this dialog defaults to having all applicable file extensions, such as
.pas, opened with the Lazarus IDE. If you also have Delphi installed, you may want to consider changing these options.
Although Lazarus is targeted mainly for Linux and Windows operating systems, there are also binary packages available for Mac OS X. FreeBSD makes Free Pascal and Lazarus available through its ports collections. It is also possible to run Lazarus on other operating systems, such as Haiku, by compiling Lazarus and Free Pascal from source.
Lazarus and Free Pascal are available as disk images (
.dmg files) for Mac OS X for Intel-based Macs and PowerPC-based Macs from the SourceForge.net Repository at http://sourceforge.net/projects/lazarus/files/. The Mac OS X versions of Lazarus require the installation of Apple Developer Tools. This can be installed from the Mac OS X installation disks or downloaded from the Apple Developers Connection (ADC) at http://developer.apple.com. ADC requires registration, which is free. Once these tools have been installed, go to the SourceForge.net repository and select the correct subfolder for your Mac, Lazarus Mac OS X PowerPC, or Lazarus Mac OS X i386. Then choose the latest release of the Lazarus subfolder, which is Lazarus 1.0.2 at the time of writing, and download the disk images. For Mac OS X PowerPC, download the following:
Once the disk image files are downloaded, install them in the following order:
fpc: The Free Pascal compiler
fpcsrc: The Free Pascal compiler source
lazarus: The Lazarus IDE
After installation, the Lazarus application can be found in
/Developer/lazarus, the Free Pascal source files are in
ports collection contains, at the time of writing, 91 separate ports for Free Pascal. These ports are divided into subcategories such as
multimedia. This is in keeping with the FreeBSD philosophy of only installing necessary packages to keep this system as small as possible and easily maintainable. For Lazarus, the ports collection contains six separate ports; among them are GTK+, GTK2+, and Qt toolkit versions of Lazarus. The simplest way to install Free Pascal is to log in as a root user and issue the following commands:
# cd /usr/ports/lang/fpc # make install clean
This will install the Free Pascal meta port. Meta port
in FreeBSD is a port that installs multiple sub ports. In this case, the
fpc meta port will install all 91 Free Pascal port. In addition to these ports, any requirements not installed on the system will also be automatically installed. If you are an advanced FreeBSD user and know exactly the type of development you are going to do with Lazarus and Free Pascal, you can install only the needed individual ports of the 91 available.
The easiest way to install Lazarus is to use the meta port located in
/usr/ports/editors/lazarus. Remain logged in as root and issue the following commands:
# cd /usr/ports/editors/lazarus # make config
This will bring up the Options for Lazarus dialog box as seen in the screenshot that follows. In this dialog, you can choose to either install the GTK2 interface or the QT4 interface for the IDE. You can only choose one of the two options, choosing both will cause an error during installation.
After selecting the desired interface and selecting OK, continue installing by issuing the following command:
# make install clean
Once the installation is complete, Lazarus will be installed in
/usr/local/bin and can be started with the following command:
For operating systems that don't have a binary package available, Lazarus can be built using the source code.
Lazarus and Free Pascal source code is available through Subversion (SVN). The SVN repositories provide the most up-to-date source code available. The SVN repositories also allow you to track only the changes in the source. Although, SVN access requires an Internet connection, it does not require the user to be root.
When downloading the source, you need to make sure that you have enough free space. The initial checkout requires approximately 270 MB of free space. To begin the installation from source, first make sure that current working folder is the folder that you want the source code to be present in. For the initial checkout, use the following command:
$ svn checkout http://svn.freepascal.org/svn/lazarus/trunk/ lazarus
This will download the latest available source code to the
lazarus subfolder, which will be created in the current folder. Once the download is completed, compile the source code by using the following command:
$ cd lazarus $ make
Once the build is complete, Lazarus can be started from the current folder with the following command:
To keep Lazarus up-to-date, from the parent folder of the Lazarus source code, use the following commands:
$ svn update lazarus $ cd lazarus $ make clean all
This will rebuild the Lazarus IDE without packages. After the build is done, then use the following command to link to the existing Lazarus packages:
$ ./lazbuild –build-ide=
After a successful installation of Lazarus and Free Pascal, it may be necessary to set up a few environmental settings so Lazarus can function correctly. Start Lazarus on the initial start up. You may see the informational error notifying that Lazarus cannot find the Free Pascal source directory. To correct this, open the Lazarus IDE Options dialog which looks like the screenshot that follows. The IDE Options dialog is accessed under the Environment menu and the Options submenu.
When you initially access this dialog, you can see that the FPC source directory textbox is empty, click the ellipse button and enter the source directory path.
For Linux/BSD, enter the following:
For Windows, the IDE Options menu is located under the Tools menu. The default Free Pascal source folder is
If you did not install Lazarus using the defaults, choose the folder in which you installed Lazarus.
Another import option that is not set in the Linux version is the debugger. To access the debugger settings, scroll down in the left window of the Options menu and select Debugger. In the right window pane, select the drop-down box with the heading Debugger type and path. Select the GNU Debugger (gdb) option. Once selected, the path should populate itself.
In this chapter we learned that Lazarus is an open source integrated development environment for the Free Pascal language that is similar to Delphi. Lazarus contains the LCL, which is its version of Delphi's VCL. Lazarus can be used to create console as well as GUI applications. Because of its similarities to Delphi, it can be used as a replacement for Delphi.
Lazarus can be installed on Linux platforms either by using the package management tool of the specific Linux distribution or by installing it from the binary or source files located on the SourceForge.net repository.
Lazarus can also be installed on the Windows platforms, either 32-bit, or 64-bit using the packages available on the SourceForge.net repository.
There are also
.dmg package files available at SourceForge.net for installing Lazarus on Mac OS.
The FreeBSD project makes Lazarus available through its ports system. There are 91 separate packages related to Lazarus and Free Pascal. There is also a meta package that will install all the separate packages or a subset thereof.
We learned how to set up the IDE options for the FPC source folder and the GNU debugger.
With the successful installation and updating of the settings, we now have a basic Lazarus development environment. We are ready to take on programming with Free Pascal and Lazarus, but first let's take some time to familiarize ourselves with the Lazarus IDE.