Lazarus for Cross-Platform Development

 in
Lazarus may be the most native cross-platform development environment running on Linux, Windows and Mac OS X. Use it to create native applications with platform-independent code.

Lazarus is an open-source library of visual components and a powerful IDE for rapid cross-platform development. The IDE contains all the features of a modern development suite, including a debugger, code completion, visual designers, refactoring tools, and translation and documentation tools. The Lazarus Project started on Linux ten years ago and now runs on all major platforms: Linux, Windows and Mac OS X. The Lazarus Project's motto is “Write once compile anywhere”, and it provides cross-platform libraries, a cross-platform compiler and a cross-platform IDE.

Lazarus' features include the following:

  • An easy-to-learn language: Pascal.

  • A visual form designer.

  • Producing native code executables that execute with speeds comparable to C/C++—no virtual machine here!

  • Allowing direct access to system libraries.

  • Supporting embedded assembler code.

  • Easily handling big projects with millions of lines.

  • Compatibility with the Delphi visual component library.

And, if all that weren't enough, Lazarus also is open source and free of charge, even for commercial development. The Lazarus IDE is shown in Figure 1.

Figure 1. Lazarus IDE

Free Pascal Compiler

Lazarus uses the powerful Free Pascal Compiler (FPC), which understands Object Pascal (a descendant of Pascal). Free Pascal (aka, FPK Pascal) is a 32- and 64-bit professional Object Pascal compiler. It is available for the following operating systems: Linux, FreeBSD, Mac OS X/Darwin, DOS, Win32, Win64, WinCE, OS/2, Netware (libc and classic) and MorphOS, and for different processors: Intel x86, AMD64/x86_64, PowerPC, PowerPC64, SPARC and ARM. You can find binaries, packages and daily snapshots at the Free Pascal and Lazarus Web sites (see Resources). Free Pascal creates native code executables, like C and C++, and uses the GNU tools and object format, so it can use C libraries directly, and, of course, C/C++ code can use FPC libraries. The speed and size of the created code is comparable to GCC.

FPC also compiles fast—normally more than 10,000 lines of code per second. That is because in Object Pascal, forward declarations are more limited than in C/C++. This saves a lot of time, even for small programs, and allows you to be more productive. After a while, you'll compile without thinking, just to highlight even obvious errors.

The Free Pascal Compiler itself is written entirely in Object Pascal. At the time of this writing, the compiler is at version 2.2.4.

Like its ancestor Pascal, Object Pascal is very easy to learn. C and Java programmers will understand most Pascal code without any tutorials. The language is very type-strict, and many code inconsistencies are spotted at compile time. This is especially useful for big projects, when a refactoring eventually is needed, and all affected places must be found. The compiler also warns when a statement works on the current platform but may fail on another—for example, when an expression works differently on 32- and 64-bit systems.

Lazarus Component Library and the IDE

Lazarus gives FPC a face by providing the Lazarus Component Library (LCL), a library of visual components, such as buttons, edit fields, file dialogs and much more. These components run on Linux, MS Windows, Mac OS X, FreeBSD and Solaris using native widgets. Additionally, on Linux, you have the choice between GTK or Qt as a back end. The LCL calls the back-end widget sets and provides the glue between the platform-independent API and the widget set. The code itself needs to access only the LCL API, so no change is required when switching the widget set.

An LCL application compiled with GTK creates a native GTK application running on most Linux distributions out of the box. Under Windows, the choices are the WinAPI, GTK and Qt. For Windows CE, the back end is called wince. Under Mac OS X, the choices are Carbon, GTK and Qt. The widget set can be chosen automatically by the IDE or selected manually in the dialog for the compiler options. This allows you simply to copy a project developed under Linux to Windows and compile.

Some other LCL interfaces are under development—for example, fpgui, a widget set written completely in Object Pascal and Cocoa for the new Mac OS X libraries. So, if you don't care about native widgets and you want your application to look and feel exactly the same on all platforms, you can make use of the LCL and the fpgui library, which currently runs on MS Windows, MS Windows CE and Linux with X.

The Lazarus IDE uses the LCL and has an integrated visual form designer, which allows you to edit forms graphically, like Glade or Trolltech's Qt Designer. Lazarus' designer works directly with the corresponding Pascal unit source. For instance, double-clicking on a button in the designer automatically creates the OnClick in the source code and connects the button and the event handler. No further work is needed—simply compile and run. And, it works backward too. Remove a method from the code, and the IDE will disconnect it from the designed form.

The IDE even supports connecting two designed forms. That means a component on form1 can access the components on form2. No extra source code is required for this, just some mouse clicks.

The designer also allows you to inherit forms visually. For example, a base form can be created for all of an application's dialogs. Descendants can be created visually that inherit from this dialog. No extra source code is required. Even embedding a form into another form as a subcomponent can be done visually.

Of course, everything done in the designer can be done via source code at runtime too. The form data is stored in .lfm files, which are simple text files, so they are cross-platform also.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Finnally, I have made a Puppy Linux remastered with Lazarus.

Alejandro Lavarello's picture

I have tried months to install Lazarus 0.9.28.2 in Puppy Linux 4.3.1, and I finally have success!

The result is a .iso file , 330MB : just burn to CD , reboot your PC and start developing in Lazarus!!

The MD5 sum is fa94102ecf1bf5c29f629148667399fc , and you can download from one of these locations:

1)http://www.megaupload.com/?d=10836C0B

2) http://www.puppyisos.org/isos/2009-07-to-12/
(user: puppy , password: linux)

You need a PC with at least 480MB of RAM, because all is loaded in memory; yes, I know, it is a disadvantage.

Another way is to install plain Puppy 4.3.1 (Frugal installation on disk), with devx_431.sfs and this .sfs created by gposil,
http://gposil.com/dpup/lazarus-0.9.28.2-complete.sfs

In this way, you can run Lazarus in a PC with 128MB of RAM.

I hope this will help people that have trouble installing Lazarus in Linux.

No garbage collection

Anonymous's picture

Free Pascal lacks garbage collection and you can't even have smart pointers like in C++. Manual memory reclamation is not a feature of a modern language.

Oh please

Anonymous's picture

garbage collection is only making mess. Who cares if you get a memory leak due to unhandled exception? Nobody. Good programmers know how to manage memory and don't need anything else thats only slowing app down...

Why is so difficult to install Lazarus in Puppy Linux?

Alejandro Lavarello's picture

I am a electronic technician and have used Borland Pascal for controlling devices. When Windows 95 becomes popular, I cant obtain Delphi, and have programmed in Visual Basic. Now, I am interested in programming in Lazarus. I am using the Puppy Linux distro, but I am tired to trying to make Lazarus work. Please, anybody can make a .pet or a .sfs or a Puppy remastered with Lazarus working?

Another question: why the Lazarus installer do not contain ALL the stuff? In Windows, Lazarus installs without problems. But I am disappointed with Linux, because each distro neeeds different installation procedures. This is a great Linux failure.

> why the Lazarus installer

Anonymous's picture

> why the Lazarus installer do not contain ALL the stuff?

Because the dependencies can be obtained easily from distro's repository, and it's of course a waste of space to include the installer along with them. Another problem, those dependencies depends on installed libc version which can't be predicted easily. Free Pascal (and therefore, Lazarus) itself is OK since they're not linked againts libc.

Every Linux distro is a separate world

Anonymous's picture

I see .deb and .rpm installers for Lazarus.
It is a shame that every Linux distro has different installer packages.
For end user, each distro is equal to a different operating system.

Writing components

Motaz's picture

I'm using Delphi for more than 10 years, and following Lazarus for many years. Thanks to Lazarus, I discovered a new area of developments, which is component development. Lazarus is needing a lot of components and packages. It is very easy in Object Pascal language to write a package.
Now I'm doing a web development components similar to Delphi's WebBroker. Now CGI part is working. I'm developing this component under Linux and it works just fine under Windows without any modification.
They only problem that I faced in Linux is Arabic language support in linux. Current stable version is still using GTK 1, and Unicode support is exist in GTK+2 which supported by not-stable daily snapshots.
Fortunately I can use Arabic with my web applications under linux, because no need for GTK1 or 2 :)

> Current stable version is

Anonymous's picture

> Current stable version is still using GTK 1, and Unicode support > is exist in GTK+2 which supported by not-stable daily snapshots.

AFAIK since version 0.9.26.2 GTK2 is already set as default widgetset on linux, marking its stability has reached a suitable point for development. Either you're using an older version or you take a conslusion from the wiki (which is often not up to date).

I'm using 0.9.26.2 and the

Anonymous's picture

I'm using 0.9.26.2 and the default is set to GTK, GTK2 is marked as beta still.

Pascal as language has been

Javier Santo Domingo's picture

Pascal as language has been understimated too much, but it features many important things since its creation. And more: it has evolved really well, in many ways in many of its dialects. I think it has what it takes to be the next king of strongly typed languages.

Compiler speed is important

Mario Ray Mahardhika's picture

Many programmers state that compiler speed isn't that important compared to generated code quality. Imaging you're working on a big project that gets changed very often, how long do you spend time watching your compiler compiling your code?

My experience in building large projects, such as QT and GCC, shows that compiler speed is important. QT took 6 hours to build (even with make -j 256!), GCC bootstraps itself (compiler, binutils, standard libs) in more than an hour.

FPC and Lazarus are also big complex project. But do you know how long does it take to build both (for FPC, it includes compiler, helper tools, IDE, standard libs, and tons of extra libs)? 10 minutes! This is a great time saver everybody!

My First project with lazarus is done!

liangby's picture

About 2 years ago, I porting a win32 application writing in delphi to linux.The first choice is kylinx, But it is too old for most linux, very hard to use on Centos 5. But I found lazarus, It help me complete that. And the application had sucessed runing on Centos and ubuntu, is cost down about 1,000RMB for me/PC!
A great project!

We do Delphi development so

Anonymous's picture

We do Delphi development so when the time came to start developing applications for use on Linux systems, Free Pascal and Lazarus seemed like the natural choice. Free Pascal is really quite nice, but unfortunately Lazarus isn't quite as nice. After using Lazarus on a number of projects we found it still had too many problems to make it worth while to continue using it. There were always large regressions between major Lazarus releases. Every time we upgraded we had to spend time figuring out why the applications that used to work just fine in the previous release suddenly no longer worked the same in the current release.

Eventually we abandoned Lazarus and moved to just building Win32 applications and running them with Wine. This approach, of course, had issues of its own but once the teething problems were sorted out our applications ended up working better and with more features than their Lazarus-based ancestors. This is partly because there is simply more choice of components and libraries for Delphi than there is for Lazarus, partly because there was a lot of code we could reuse between the "Linux" applications and the "Windows" applications, partly because the Delphi development environment is stronger than Lazarus with more and better integrated tools, and partly because the Delphi + Wine platform has by and large turned out to be more stable.

Back to Pascal? I Can Hope!

Ro's picture

Like Paulo Pinto, I cut my teeth on Pascal in the MS-DOS days and was sad to see it disappear under the weight of C and, particularly, C++.

The object-oriented versions that limped along simply seemed to be half-baked hotch-potches.

Perhaps this will give me a way back to multi-platform Pascal. Goodness knows, it would make my life much easier!

Thanks for the review :-)

Lazarus vs Delphi

Anonymous's picture

Lazarus has still a long way to go comparing it with its commercial competitor Delphi.
Don't get me wrong: I would love using Lazarus if it would compile faster and create smaller binaries, but most important, it has to be rock stable.
I'm a using Delphi as a professional developer for about 10 years now.

Oh come on!!!

Anonymous's picture

When did Pascal become "an easy to learn language"? It shouldn't come as a surprise that it is not in widespread use since it works only with Pascal which..... need I say isn't much used these days. Extending the IDE is always nice but there aren't too many third-party plugins available for it.
Nice review of Lazarus though.

Pascal was always a nice

Paulo Pinto's picture

Pascal was always a nice language. Did you know that the first versions of MacOS were written in a mixture of Pascal and Assembly?

I remember the days were most of my MS-DOS coding was done in Turbo Pascal, and even my first coding attempts in Windows 3.x were done in Pascal.

But C got more widespread, mainly thanks to C and having a language standard defined more tailored for doing systems programming.

The Pascal standard was only suited for teaching and we had to rely on manufacturer extensions to be able to do real life applications. When the second revision of the standard came out, it was already to late.

For me, Pascal will always have a place on my heart.

I'm working with lazarus for

devel's picture

I'm working with lazarus for years and it is amazing!
It is great to compile it in linux and windows with excactly the same code!

Cross-platform is a breeze

Graeme's picture

Excellent article Mattias! Our company moved over to the Free Pascal Compiler and Lazarus IDE four and a half years ago. The support is fantastic, the products are very stable and development is continuous.

The Object Pascal language is also very nice - miles ahead of the old Pascal from the 80's. A clean and strongly typed language that you can learn very easily. It supports full object oriented programming and combined with a very fast compiler and excellent component libraries, this is a win-win situation for any developer or company. Object Pascal deserves a lot more attention in the developer circles.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix