Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with Lazarus IDE
Getting Started with Lazarus IDE

Getting Started with Lazarus IDE: Get to grips with the basics of programming, debugging, creating, and documenting projects with the Lazarus IDE

By Roderick Person
Free Trial
Book Feb 2013 116 pages 1st Edition
eBook
zł87.99 zł59.99
Print
zł108.99
Subscription
Free Trial
eBook
zł87.99 zł59.99
Print
zł108.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details


Publication date : Feb 22, 2013
Length 116 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782163404
Vendor :
Embarcadero Technologies
Category :
Table of content icon View table of contents Preview book icon Preview Book

Getting Started with Lazarus IDE

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.

Left arrow icon Right arrow icon

Key benefits

  • Creating new projects
  • Create components for use in Lazarus
  • Documenting Lazarus project

Description

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.

What you will learn

Install Lazarus on different platforms such as Linux or Windows Learn the basics of the Lazarus IDE such as the menus, the Object Inspector, and the Source Code Editor Create new projects with Lazarus such as console applications and GUI applications Debug Lazarus projects Convert an existing Delphi project to a Lazarus project Create new components for use with Lazarus GUI applications Document a Lazarus project using the LazDE tool Rebuild Lazarus on the Windows platform using the GTK 2 widget set  

What do you get with a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details


Publication date : Feb 22, 2013
Length 116 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782163404
Vendor :
Embarcadero Technologies
Category :

Table of Contents

14 Chapters
Getting Started with the Lazarus IDE Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewer Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
1. Installing and Configuring the Lazarus Development Environment Chevron down icon Chevron up icon
2. Getting to Know the Lazarus IDE – a Quick Tour Chevron down icon Chevron up icon
3. Creating a Hello World Program Chevron down icon Chevron up icon
4. Converting Delphi Chevron down icon Chevron up icon
5. Creating a Lazarus Component Chevron down icon Chevron up icon
6. The Lazarus Documentation Editor Chevron down icon Chevron up icon
7. Rebuilding Lazarus with a GTK2 Interface Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.