[Lazarus] Linking dynamic libraries

Sven Barth pascaldragon at googlemail.com
Sun Dec 30 16:54:01 CET 2012


On 30.12.2012 16:47, xrfang wrote:
> Hi All,
>
> While I compile my program which uses liblua52.so, Lazarus refuse to
> compile if it cannot find the so file.   But on windows, it compile
> happily without the DLL file.
>
> As far as I understand dynamic link libraries are only required at
> runtime, why lazarus require it on compilation?

First you need to understand that libraries can be dynamically linked in 
two ways:
* at runtime
* at linktime

The first case is when you (or e.g. an unit) does a LoadLibrary and 
manually queries for each function it needs (often done by the database 
units provided by Lazarus). The other method is used when you have 
methods declared with "external Bar name Foo". Then the library name and 
the functions that are imported are mentioned in the import section of 
the resulting executable and the OS loader ensures that the libraries 
are loaded and initialized before the main application starts. If such a 
library is missing at program startup you'll get an error message.

And here is where a difference between Windows and Unix systems lies 
(Note: your lua52 unit uses the second case): on Windows it is enough to 
know the library name and the function name and if the library is 
missing at link time this doesn't matter. On Unix though you must have 
the library available, because the linker needs information that is only 
provided inside the library file itself, because the filename is less 
important on Unix systems.

So this is not the fault of Lazarus (or Free Pascal to be more precise, 
as Lazarus is only the IDE which calls FPC), but of the different 
concepts used on Unix.

Solution: just install the dev package of your distribution and it 
should work.

Regards,
Sven





More information about the Lazarus mailing list