Lazarus for Cross-Platform Development

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.
FPC: the Cross-Platform Foundation

Lazarus provides an outstanding native code solution. The compiler and most libraries are written with cross-platform in mind. That is why programs written in Free Pascal do not need to run a configure script before compilation. The base types, like char, byte, integer and string, work the same on all platforms. An integer always is a signed 32-bit value. The 64-bit integer is called int64. The native integer for a processor is called PtrInt for signed and PtrUInt for unsigned values. Lazarus itself can be compiled with a simple make or graphically in the IDE itself. And, of course, Lazarus is developed with Lazarus.

FPC's runtime library does not use libc; rather, it uses kernel functions, which change less often. Therefore, the created executables normally work on various Linux distributions and do not need to be recompiled for each new glibc version.

With Lazarus, you can write and debug the biggest part under Linux. But eventually, you'll need to test it on the other targets. However, you do not need to install Lazarus and all the development tools on all your target platforms. Cross compiling can be used to develop under Linux and target another operating system or processor. For example, you could develop under Linux and create Windows executables, and then test them with Wine or in a virtual machine running Windows, or on an actual Windows system. Cross compiling is a big time-saver, because it allows you to test on several platforms quickly and to use your favorite programs while developing.

Note, however, that cross compiling does require you to install the cross-compile tools and libraries, which can be tricky. Precompiled versions do not yet exist for all possible hosts and targets. Easy directions are provided for Linux to Windows, because of Wine, and for Windows to Windows CE, because there are installers with all needed tools.

Setting Up Cross Compiling

First, you need to cross compile and install the GNU binutils. This is well documented on several sites, including the Lazarus Wiki (see Resources). For many targets, this is as simple as downloading a single tar.gz and running a script with some parameters.

The next step is to cross compile the Free Pascal libraries. If you want to cross compile to another processor type, you need to cross compile the compiler too. Again, for many targets, complete scripts are available.

If your program requires third-party libraries, these must be cross compiled too. If they are written completely in Object Pascal, normally you can just compile them. Lazarus will do that automatically for you. If they use system libraries, it can become difficult. The problems are then the same as for C/C++ compilers.

Once you've installed the cross compiler and libraries, cross compiling becomes easy in Lazarus. Simply pass the -T option to the compiler. For example, pass -Twin32 to compile a 32-bit Windows executable instead of a Linux binary. The -P option defines the target processor. Normally, you don't even need to pass special search paths, because of the path scheme used. For instance, the Pascal units for the fpc 2.3.1 compiler, for the processor type i386, and for target operating system Linux are installed under /usr/lib/fpc/2.3.1/units/i386-linux/. All filenames and search paths of the compiler and the IDE support macros, which greatly reduces the amount of command-line parameters and configuration settings.

Lazarus reduces the amount of platform-specific settings even further. The IDE allows you to combine several source directories into a Lazarus package. A Lazarus package can be a library or just a logical module of a big project. A package has its own search paths, its own compiler settings and its own macros. All filenames and search paths are stored relative to the configuration file (.lpk file). A package can use other packages and inherit search paths and compiler settings. You can store a package anywhere on the disk. All search paths are adapted automatically on the fly. And, because every source has its own namespace, there is seldom a name conflict. You can switch to another version simply by opening the .lpk file. Each package also has its own output directories, normally one for each platform, which are created automatically.

When a package's source file is changed, the IDE automatically compiles the package and all packages in the current project that depend on it. You can fine-tune this automation for each package.

When you switch the target platform in the IDE, all packages' output directories are switched. The compiler options dialog is shown in Figure 2.

Figure 2. Lazarus Compiler Options



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 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:


(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,

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 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 and the

Anonymous's picture

I'm using 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.