Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-12

Linking dynamic libraries

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

xrfang

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?

Thanks,
Shannon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121230/721a4563/attachment.html>

Reply by email

Sven Barth
to xrfang
xrfang wrote 8 lines
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

Reply by email

Michael Van Canneyt
to xrfang: While I compile my program which uses liblua52.so, Lazarus refuse to compile if it cannot…
xrfang wrote 5 lines
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?

Because on unix you need them also at link time.

You must install the -dev package corresponding to the library.

Michael.

Reply by email

leledumbo
to xrfang: While I compile my program which uses liblua52.so, Lazarus refuse to compile if it cannot…
As far as I understand dynamic link libraries are only required at runtime,

why lazarus require it on compilation?

Not in *nix world. The inner workings between .dll and .so are different.

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Linking-dynamic-libraries-tp4028332p4028335.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

xrfang
to Sven Barth: First you need to understand that libraries can be dynamically linked in two ways: * at…

It's clear now. ?One more question, I just installed liblua5.2-0 and it linked happily, what else does the "dev" package offer for development?

Thanks,
Shannon

? ?, 12? 30, 2012 at 11:54 ???Sven Barth ???

xrfang wrote 8 lines
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

Reply by email