[fpc-pascal] Can FPC link a program with static (.a) libraries on Windows

Sven Barth pascaldragon at googlemail.com
Sat Feb 17 01:29:03 CET 2024


Tony Whyman via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Sa., 17. Feb. 2024, 00:50:

> I have a Pascal program, compiled with FPC 3.2.2 and which appears to
> happily link and run with a static library compiled with gcc and having
> a ".a" prefix on linux. The functions in the static library and declared
> as external functions using the "external <libname> name <function
> name>" directive. The "".a" library is copied to the same directory as
> the program unit before compiling and linking.
>
> However, compiling the same program on Windows always seems to result in
> the loader complaining that the corresponding <libname>.dll is not
> present, indicating that instead of linking with the static library, the
> program is attempting to "statically" load the correspoinding dll at
> initialisation time.
>
> I have tried to force it to link with the static library (e.g. using the
> -Xt command line switch) but no luck.
>
> Hence the question, does FPC 3.2.2 support linking with static libraries
> on windows?
>

"external <libname> name <funcname>" is for dynamic linking. For static
linking you need to leave out the <libname> and instead use "{$linklib
<libname>}" or even "{$linklib <libname>, static}" . That will also work on
Linux.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20240217/9b80acdc/attachment.htm>


More information about the fpc-pascal mailing list