Home Programming Getting Started with Lazarus IDE

Getting Started with Lazarus IDE

By Roderick Person
books-svg-icon Book
eBook $16.99 $10.99
Print $26.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $16.99 $10.99
Print $26.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
About this book
A good integrated development environment can be the key to creating and delivering software on time and budget. Having a programming language and a development environment that runs on multiple platforms greatly eases and lessens the time taken on creating cross-platform applications. An IDE that is compatible with a legacy code base allows developers to leverage existing libraries in future applications."Getting Started with Lazarus" is a practical, hands-on guide that provides you with a number of clear step-by-step exercises, which will help you take advantage of the power of the Lazarus IDE and Free Pascal to develop software that can be created for cross-platform use."Getting started with Lazarus" discusses developing software with the open source cross platform integrated development environment and the Free Pascal language. We'll learn how to install Lazarus on various platforms such as Linux and Windows, as well as how to create new projects and convert existing Delphi projects to Lazarus projects by learning the differences between Delphi's Pascal syntax and Free Pascal's Object Pascal using a real world example project. We'll learn how to create custom components for use in Lazarus. We'll also learn the basics of documenting a Lazarus project using the Lazarus Documentation Editor. Finally we will learn that the IDE can be rebuilt using a different widget type, specifically GTK 2. Teach yourself the basics of programming with Lazarus and the open source IDE for the Free Pascal language.
Publication date:
February 2013
Publisher
Packt
Pages
116
ISBN
9781782163404

 

Chapter 1. Installing and Configuring the Lazarus Development Environment

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

 

Why 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.

 

Installing Lazarus in Linux


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.

Downloading and installing the Lazarus Linux RPM package

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:

  • Lazarus-1.0.2-1.i386.rpm

  • fpc-src-2.6.0-0.laz.i686.rpm

  • fpc-2.6.0-0.laz.i686.rpm

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.

Requirements

Before installing Free Pascal and Lazarus, the following programs are required on the Linux system:

  • GNU as the GNU assembler

  • GNU Id or the GNU linker

GNU Make, this is optional but recommended for easy recompiling of the FPC compiler and Run-Time Library (RTL).

Lazarus requires the following libraries:

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.

Downloading and installing the Lazarus Linux DEB package

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:

  • lazarus_1.0.2-0_i386.deb

  • fpc-src_2.6.0-120824_i386.deb

  • fpc_2.6.0-120824_i386.deb

For 64-bit systems:

  • lazarus_1.0.2-0_amd64.deb

  • fpc-src_2.6.0-120824_amd64.deb

  • fpc_2.6.0-120824_amd64.deb

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.

Lazarus for Ubuntu

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 -

Next, add the repository by editing /etc/apt/sources.list, adding the following line:

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
 

Installing under Windows


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 lazarus-1.0.2-fpc-2.6.0-win64.exe.

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.

 

Installing under other OSes such as FreeBSD or Mac OS X


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.

Installing Lazarus on Mac OS X

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:

  • fpcsrc-2.6.0.powerpc-macosx.dmg

  • fpc-2.6.0.powerpc-macosx.dmg

  • lazarus-1.0.2-powerpc-macosx.dmg

For Mac OS X Intel:

  • fpcsrc-2.6.0.powerpc-macosx.dmg

  • fpc-2.6.0.powerpc-macosx.dmg

  • lazarus-1.0.2-20121009-i386-macosx.dmg

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 /usr/local/share/fpcsrc.

Installing under FreeBSD

The FreeBSD ports collection contains, at the time of writing, 91 separate ports for Free Pascal. These ports are divided into subcategories such as graphics, math, and 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:

$ /usr/local/bin/startlazarus

For operating systems that don't have a binary package available, Lazarus can be built using the source code.

Installing from source

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:

$ ./startlazarus

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=

Tip

If you are building from source on a BSD-based system, you will need to use gmake instead of make.

On the Windows platform, if you have Delphi installed, you must modify your PATH variable or delete the Delphi version of make.

 

Configuring the Lazarus development environment


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:

/usr/local/src/FPC

For Windows, the IDE Options menu is located under the Tools menu. The default Free Pascal source folder is c:\lazarus\fpc\2.6.0\source.

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.

 

Summary


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.

About the Author
  • Roderick Person

    Roderick Person has a varied background in the corporate IT field. For the last 14 years he has been a programmer for one of the top ranked health systems in the United States. He is experienced with developing applications in Delphi, Free Pascal, Python, SQL, and other languages. He is also an advocate of leveraging open source applications in corporate environments.

    Browse publications by this author
Latest Reviews (2 reviews total)
Aindo estou aprendendo. Era difícil achar livro neste assunto,
Getting Started with Lazarus IDE
Unlock this book and the full library FREE for 7 days
Start now