Sie sind auf Seite 1von 2

Chapter 5 Target Platforms

By Felipe Monteiro de Carvalho

Lazarus programs can be compiled to run on three major computer platforms: Windows, Linux/Unix, and MacOS X. That is fewer platforms than the Free Pascal compiler is able to target. The reason for this is that appropriate compiler capability is not the only condition that must be met before you can create a Lazarus program for a new platform. The following three conditions have to be fulfilled before you can install and use Lazarus on any platform: A current Free Pascal compiler for the target platform must be available. At the moment these are available for Windows 32, Windows 64, Windows CE, MacOS X, Linux, FreeBSD and OS/2 (and eComStation) and (to a certain extent) for Solaris. A current Free Pascal compiler for the target CPU must be available. At the moment these are available for x86, x86_64, PowerPC, PowerPC64 and Arm (ARM4-instruction set only the THUMB instruction set is not supported). There must be a GUI library available for the operating system platform. Currently fully supported are Windows, Windows CE and MacOS X, and also the Linux/Unix widget-set Gtk versions 1 and 2, and the platform-independent Qt 4 (Unix, MacOS, Windows). This third requirement is the reason it is not possible to create OS/2 programs with Lazarus. A Free Pascal compiler for x86-OS/2 exists, but there is no support for the OS/2 presentation manager and for eComStation. In theory it should be possible to install Lazarus under XFree86/2 and create OS/2 programs for X. Nobody has tried this yet, but all the requirements can be met: there is a compiler and there is a port of Gtk version 2. There are huge differences between the four basic platforms Win32/64, WinCE, MacOS and Linux/FreeBSD/Solaris. For that reason it is important if you want to create applications to run on multiple platforms (or if you intend to port software from one platform to another) to get acquainted with the details of using Lazarus on each of these platforms before making a start. That way you can investigate beforehand what problems you might encounter, and so make the right choices when designing software to run on all the desired platforms without problems. With some experience you can then develop software completely on one platform, and simply recompile your program to make it available on additional platforms.
Lazarus - the complete guide

279

Chapter 5 Target Platforms .

This chapter gives a general overview of this theme, explaining the main features of the different operating systems, and also shows you how to make use of the native APIs if necessary (although you should normally avoid doing this if you are trying to create portable software). At first sight it would seem very easy to make sure programs developed with Lazarus will run on all platforms. If you use only libraries that exist on all target platforms, and if you use only calls to the Free Pascal RTL and FCL and to the Lazarus LCL your programs will work on all supported platforms, in theory, without change. In theory because there are still many operating system differences to keep in mind. If everything is done in the right way the RTL, FCL and LCL will hide or minimise these differences, but we may also have to work around them (and if the need arises we may have to correct code manually). It gets more difficult if we need functionality that is not provided by Lazarus's libraries. It that case we will be forced to find another library that does offer such functionality on multiple platforms (hopefully on all of them), or we will have to work with the low-level APIs of each operating system to implement a solution for each platform ourselves. In these cases we will have to use conditional compilation. When we do that, parts of the source code for the different operating systems will need to be separated. Free Pascal offers the sequence of commands $ ifdef condition . . . $else . . . $endif to facilitate this. However, having to interlace source code for different operating systems in large routines in this way is not ideal. A cleaner solution is to provide separate source files, each offering a solution for one of the platforms. A good way to handle this in Free Pascal and Lazarus is to make use of the meta-command $include filename.inc to include these parts of the code into the source. A common convention is to create one subdirectory per platform and put all platform-specific code in the appropriate subdirectory. Anything between the conditional commands $ifdef and $endif will be used only if the condition given after $ifdef is True. This applies to the include statements too. We can include a file for just one operating system with a one-line construction in the code.
{$ifdef Linux} {$include linux.inc} {$endif} {$ifdef Win32} {$include win32.inc} {$endif} / / . . . etc .

A more elegant way is to use macros in search paths. If we include $(TargetOS) in the search path for include files, we can simply use:
{$include unit1.inc}

In that case the include file for Win32 might be located in: Win32/unit1.inc while the include file for Linux could be found in: Linux/unit1.inc In this way all Linux-specific files can be stored together in one directory. Macros can also be used for unit search paths. 280
Lazarus - the complete guide

Das könnte Ihnen auch gefallen