search
left
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
right
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
$16.99 $10.99
Book Feb 2013 116 pages 1st Edition
eBook
$16.99 $10.99
Print
$26.99
Subscription
$15.99 Monthly
eBook
$16.99 $10.99
Print
$26.99
Subscription
$15.99 Monthly

What do you get with eBook?

Feature icon Instant access to your Digital eBook purchase
Feature icon Download this book in EPUB and PDF formats
Feature icon Access this title in our online reader with advanced features
Feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Feb 22, 2013
Length 116 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782163404
Vendor :
Embarcadero Technologies
Category :
toc View table of contents toc 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 right arrow

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 eBook?

Feature icon Instant access to your Digital eBook purchase
Feature icon Download this book in EPUB and PDF formats
Feature icon Access this title in our online reader with advanced features
Feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

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 Packt Packt
Credits Packt Packt
About the Author Packt Packt
About the Reviewer Packt Packt
www.PacktPub.com Packt Packt
Preface Packt Packt
Installing and Configuring the Lazarus Development Environment Packt Packt
Getting to Know the Lazarus IDE – a Quick Tour Packt Packt
Creating a Hello World Program Packt Packt
Converting Delphi Packt Packt
Creating a Lazarus Component Packt Packt
The Lazarus Documentation Editor Packt Packt
Rebuilding Lazarus with a GTK2 Interface Packt Packt
Index Packt Packt

Customer reviews

filter Filter
Top Reviews
Rating distribution
star-icon star-icon star-icon star-icon 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

How do I buy and download an eBook? Packt Packt

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Packt Packt

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Packt Packt
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Packt Packt

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Packt Packt
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Packt Packt

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.