7.2.3 Compiling libraries

Once you have your (adapted) code, with exported and other functions, you can compile your unit, and tell the compiler to make it into a library. The compiler will simply compile your unit, and perform the necessary steps to transform it into a static or shared (dynamic) library.

You can do this as follows, for a dynamic library:

ppc386 -CD myunit

On unix systems, such as linux, this will leave you with a file libmyunit.so. On Windows and os/2, this will leave you with myunit.dll. An easier way to create shared libraries is to use the library keyword. For more information on creating shared libraries, chapter 12, page 586.

If you want a static library, you can do

ppc386 -CS myunit

This will leave you with libmyunit.a and a file myunit.ppu. The myunit.ppu is the unit file needed by the Free Pascal compiler.

The resulting files are then libraries. To make static libraries, you need the ranlib or ar program on your system. It is standard on most unix systems, and is provided with the gcc compiler under dos. For the dos distribution, a copy of ar is included in the file gnuutils.zip.

Remark: This command doesn’t include anything but the current unit in the library. Other units are left out, so if you use code from other units, you must deploy them together with your library.