Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

Using the LCL without Lazarus

Introduction

Why would I want to use LCL and not use Lazarus?

If you want to use LCL without Lazarus, usually it means one of two things:

Is this really possible?! Don't you need Lazarus to build a Lazarus project?!

Lazarus is an IDE - a tool to make development easier. It uses the Free Pascal Compiler installed on your system to build its projects. Naturally, you do not need the graphical development tool to simply build a Free Pascal program from sources; you only need it help you develop that software easier. Basically, it is not "a program written in Lazarus" - it is "a program written in Free Pascal using the Lazarus tool".

When you download a source package on GNU/Linux and build it, you do not need to install Oracle Eclipse or Microsoft Development Studio (or whatever tool the developers used to write that program). You only need a compiler for the language the program is written in.

Lazarus comes with a component library called LCL (Lazarus Component Library). That library contains most of the "visual" components you use with Lazarus: forms, buttons. etc. Because of this, most people have gone under a false impression that you can only build Lazarus projects using the Lazarus IDE. That is not correct; to build an application created with Lazarus, you need LCL, but you do not need Lazarus.

Why would I want to build a Lazarus project without Lazarus?

What do I really need to build my projects?

If you are downloading Lazarus from the website

Windows

If you are using Windows and downloading Lazarus from the website, then you will get everything in one folder: Lazarus, LCL and Free Pascal Compiler. If you just want to build Lazarus projects, then you don't need Lazarus itself, and you can safely delete it. Then you can pack what you really need and copy it to your build machine.

You only need the following items:

Also, you don't need to "install" anything - just copy those folders.

GNU/Linux

If you're downloading a GNU/Linux version of Lazarus from the website, then you will get a DEB package, not just an archive. It's generally not a good idea to mess with it, so you'll just have to install it as it is. It will be a much more complex task to remove Lazarus from it (and most likely not worth the result). If you really want to avoid installing Lazarus, then see the next section. Alternatively, you may want to build Lazarus from source to get it all in one directory, but that is out of the scope of this article.

If you are installing Lazarus from repositories

On GNU/Linux, if you prefer to install your stuff from the repositories, then it may depend onyour distribution's packaging specifics, but here is what I can tell about Debian Jessie and Raspbian Jessie (so it probably applies to most other distributions, too).

What you need is:

The easiest way to install them is:

This way, you do not have to install another 400 megabytes worth of Lazarus IDE, documentation and sources for Free Pascal Compiler.

So, how to build a Lazarus project without Lazarus?

The easy way

Use lazbuild. It does NOT launch Lazarus; it's just a wrapper for fpc. Running lazbuild project1.lpr should do it.

If you've installed LCL from the repositories, you'll be happy to know that lazbuild is included in the lcl package, not in lazarus package, so you can simply use it.

Note: Remember that you will have to specify the full path to the lazbuild executable unles you have its path added to the PATH environment variable.

The hard way

If you want to manually invoke fpc to build your project, then:

On your development system (the one where you do have the complete Lazarus installation) open your project, click "Project" - "Project Options", and then click the "Show options" button in the bottom. Here is the list of all compiler options used in compiling the project. You can read the fpc documentation and find out the meanings of all those options, but what we need most is the unit directories: the ones that start with -Fu and have paths in them.

If you want to build your project on the same system, then you can simply use those options without changing them. If you are planning to use them on another system, then you'll have to deduce the correct paths according to where you put the library folders. You need all three or four paths, not only the ones that include "lcl"!

You can either append them to the compiler command line (BEFORE "project1.lpr"), or you can add them to the compiler configuration file. On GNU/Linux, it is customary to pass them in a command line - that's what Lazarus does.

The fpc configuration file is located either in /etc/fpc.cfg , or in <LazarusDir>/fpc/<FpcVersion>/bin/<YourPlatform>/fpc.cfg . Just append those lines in the end of the file.

Note: Remember that you will have to specify the full path to the fpc executable unless you have its path added to the PATH environment variable.

To compile an app that uses (eg) LazUTF8, an LCL unit, you might -

fpc -Fu/usr/share/lazarus/1.8.0/components/lazutils/lib/x86_64-linux -Fu. project1.pas

If you still can not find the correct directories

If you are still struggling with those paths - for example, if you don't have Lazarus installed at all and you want to use LCL from your Free Pascal application, or you have Lazarus installed on Windows and have no idea where is LCL on GNU/Linux when installed from the repositories:

On GNU/Linux systems, the Lazarus directory is usually in /usr/lib/lazarus or /usr/share/lazarus. You can probably find it by running whereis lazarus . All the other directories should be there.

The four paths you need to specify are something like this:

bash
-Fu<YourLazarusDir>/lcl/units/<YourPlatform>
-Fu<YourLazarusDir>/lcl/units/<YourPlatform>/<YourToolkit>
-Fu<YourLazarusDir>/components/lazutils/lib/<YourPlatform>
-Fu<YourLazarusDir>/packager/units/<YourPlatform>

For example, on a 64-bit Debian:

-Fu/usr/lib/lazarus/1.2.4/lcl/units/x86_64-linux/gtk2

Or:

-FuD:\Lazarus\lcl\units\i386-win32\win32

Take a look in those directories; there is usually only one folder to choose from - not much room for a mistake.

Using LCL with Free Pascal IDE

It does not have to be a Lazarus project; you can build your normal Free Pascal project that uses LCL the same way.

Note: For some reason, I could not make fp build anything that uses LCL. I've tried adding those lines into fp.cfg and fpc.cfg, and it did build once, but then it suddenly stopped working. fpc, however, builds everything just fine. If somebody manages to do that, please update this page.


From the Free Pascal wiki, page "Using the LCL without Lazarus", as it stood on 2020-01-05 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .