Free Republic
Browse · Search
General/Chat
Topics · Post Article

Skip to comments.

Cross-Platform Development with Free Pascal 2.2.0
OS News ^ | 2007-09-10 | Joost van der Sluis

Posted on 09/11/2007 9:36:19 AM PDT by N3WBI3

Recently, Free Pascal (FPC) version 2.2.0 was released. This open source Pascal compiler has - since its initial release in 1993 - grown to be one of the most sophisticated open source compilers available today. Daily, more programmers discover FPC and develop their applications in Object Pascal. Specifically, the development of Lazarus has contributed to this phenomenon: Lazarus is a graphical open source IDE for FPC, with an extensive tool kit to design graphical (GUI) applications.

What is FPC's strength?

For many programmers, the renewed interest in Pascal is surprising. Many think of Pascal as an old language, no longer used, which has lost the battle with C a long time ago. Nevertheless, FPC has enough features to make it the language of choice for programmers.

Cross Platform

The biggest advantage of FPC is that it is cross-platform. The development of this compiler has been focused on this aspect ever since the start of the 2.0 series.

This feature removes the need for laborious writing of complicated Makefiles, which differ per platform, and which need to be generated with tools like autoconf and configure: The programmer does not need to look for all kinds of libraries: copying the compiler and the sources of the project to another platform is sufficient for porting to a new system. Obviously, cross compiling from one platform (say, Linux) to another (Windows is a popular target) is also possible.

The reason Free Pascal code is portable is simple: it offers a large set of cross-platform standard routines, bypassing the differences between Posix and Windows API's. While those can be simulated on other platforms, these simulations require cumbersome libraries and installations, and often the programs have a strange look-and-feel on the non-native platforms.

The Free Pascal compiler comes with a rich set of code libraries: The RTL (Run-Time Library) provides basic functionality such as file-access, classes, string manipulation and RTTI (Run-Time Type Information) for streaming. The FCL (Free Class Library) is an object oriented library that takes care of XML, Web programming, database access, image manipulation or a test-unit framework. As long as a programmer uses these libraries and refrains from using system-dependent APIs, his program will not only run on Linux, but also on Windows, Free BSD, Mac OS X, Windows CE and more.

It is self-evident that direct references to operating specific directories such as 'c:\program files' or a configuration file in '/etc/myprog.cfg', are not cross-platform. Using the FPC routines (for instance the TRegistry class) will take care of these operating system details: The FCL knows where and how each system stores configuration data. This almost completely removes the need for system-specific API calls.

Graphical (GUI) applications

Graphical (Desktop) applications are the norm these days. Those are not a problem: the IDE (Integrated Development Environment) Lazarus is designed with the same principles in mind as when designing FPC: The LCL (Lazarus Class Library) delivered with Lazarus makes it possible to develop desktop applications that use the standard Windows 32 or 64 API. On Linux GTK 1 or 2 is used, and both a Qt and Carbon native layer are nearing their completion.

Using Lazarus, an application can be developed on Linux, and it will use GTK. All that is needed to make a Windows version of this application is supplying a compiler option: A recompile will then produce a windows executable that works directly on any Windows version - without the need for installing extra libraries. All that is required for this is a standard Lazarus installation.

64-bits Windows

Compiling from Windows to Linux is slightly more difficult: the compiler needs the GNU linker to compile ELF binaries, and it needs to have a copy of all needed libraries available. Yet the principle remains the same. To produce windows binaries, FPC has an internal linker. This enables the compiler to generate 64-bit Windows binaries, when the GNU utilities do not yet have this ability. This makes FPC and Lazarus the first big open-source compiler and IDE for Win64.

New features for Object Pascal

In the past, the FPC added several new features to the pascal language, such as operator overloading - later also implemented by commercial compilers. New in version 2.2 is the experimental support for generics (templates). This can be useful when programming e.g. list classes.

Speed

FPC is a fast compiler: FPC compiles code roughly 7 times faster than for instance GCC. This may seem to be of little importance, but it cuts down development time. The speed of the generated code is comparable to the GCC compiler: according to the Shootout benchmarks, the FPC 2.0.4 code is 30% slower code than GCC. In contrast, FPC code uses less memory than GCC generated code. Compared to interpreted languages, one sees that FPC code executes 50 times faster than e.g. Ruby. The difference with PHP and Java is smaller, but these use 14 (PHP) to 17 (Java) times more memory than FPC programs.

One can wonder whether the speed of benchmarks says anything about real (graphical) applications. Comparing the response of the popular Java IDE Eclipse with the response of Lazarus will quickly convince one of the difference. Native code remains faster than interpreted and JIT languages, even when pre-compiled. Native code uses less memory, and is easier to install, since no extras need to be installed on the computer of the end-user.

Libraries

As remarked earlier on, Free Pascal is shipped with the RTL and FCL code libraries. The FCL comes with components for accessing databases such as Oracle, Firebird, MySQL, SQLite, PostgreSQL and any ODBC enabled database. It also contains code for XML, Web Programs (CGI and Apache modules) or access to graphical libraries such as SDL and OpenGL. Lots of Delphi components are directly usable with Free Pascal. The ZeOS database access components and the Indy networking components jump to mind. An increasing number of companies makes its Delphi libraries available for Lazarus and Free Pascal.

Conclusion

Free Pascal is a mature compiler, excellently suitable for any programming task at hand. FPC shines especially where it concerns cross-platform applications: the ease with which applications for Windows and Linux can be developed is simply astonishing. On top of this the Lazarus project offers a 2-way IDE for the development of GUI (Desktop) applications, something scarcely available for C or C++ under Linux. This domain is traditionally reserved to interpreted languages such as Java or C#, which suffer from problems such as excessive memory usage, slow performance and maintainability. All in all it can be said that the combination FPC/Lazarus is a good choice for cross-platform development.


TOPICS: Computers/Internet
KEYWORDS: opensource; pascal

1 posted on 09/11/2007 9:36:22 AM PDT by N3WBI3
[ Post Reply | Private Reply | View Replies]

To: N3WBI3; ShadowAce; Tribune7; frogjerk; Salo; LTCJ; Calvinist_Dark_Lord; amigatec; Fractal Trader; ..

OSS Ping


2 posted on 09/11/2007 9:37:40 AM PDT by N3WBI3 (Light travels faster than sound. This is why some people appear bright until you hear them speak....)
[ Post Reply | Private Reply | To 1 | View Replies]

To: N3WBI3

I didn’t know that people still program in Pascal.


3 posted on 09/11/2007 10:00:21 AM PDT by ShadowAce (Linux -- The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

Sometimes you want to use a real procedural language ;)


4 posted on 09/11/2007 10:21:58 AM PDT by N3WBI3 (Light travels faster than sound. This is why some people appear bright until you hear them speak....)
[ Post Reply | Private Reply | To 3 | View Replies]

Disclaimer: Opinions posted on Free Republic are those of the individual posters and do not necessarily represent the opinion of Free Republic or its management. All materials posted herein are protected by copyright law and the exemption for fair use of copyrighted works.

Free Republic
Browse · Search
General/Chat
Topics · Post Article

FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson