In order to use a function that resides in a library, it is sufficient to declare the function as it exists in the library as an external function, with correct arguments and return type. The calling convention used by the function should be declared correctly as well. The compiler will then link the library as specified in the external statement to your program1.
For example, to use the library as defined above from a pascal program, you can use the following pascal program:
Listing: progex/psubs.pp
This program can be compiled without any additional command-switches, and should run just like that, provided the library is placed where the system can find it. For example, on linux, this is /usr/lib or any directory listed in the /etc/ld.so.conf file. On Windows, this can be the program directory, the Windows system directory, or any directory mentioned in the PATH.
Using the library in this way links the library to your program at compile time. This means that
Or it may simply be that you don’t know the name of the function to be called, you just know the arguments it expects.
It is therefore also possible to load the library at run-time, store the function address in a procedural variable, and use this procedural variable to access the function in the library.
The following example demonstrates this technique:
Listing: progex/plsubs.pp
1If you omit the library name in the external modifier, then you can still tell the compiler to link to that library using the {$Linklib} directive.