<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body dir="auto"><div dir="auto">Thanks. Easy to forget that there are 3 ways to link to external libraries. </div><div><br></div><div align="left" dir="auto" style="font-size:100%;color:#000000"><div>-------- Original message --------</div><div>From: Sven Barth via fpc-pascal <fpc-pascal@lists.freepascal.org> </div><div>Date: 17/02/2024  00:29  (GMT+00:00) </div><div>To: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org> </div><div>Cc: Sven Barth <pascaldragon@googlemail.com> </div><div>Subject: Re: [fpc-pascal] Can FPC link a program with static (.a) libraries on Windows </div><div><br></div></div><div dir="auto"><div><div class="gmail_quote"><div class="gmail_attr" dir="ltr">Tony Whyman via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Sa., 17. Feb. 2024, 00:50:<br></div><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex" class="gmail_quote">I have a Pascal program, compiled with FPC 3.2.2 and which appears to <br>
happily link and run with a static library compiled with gcc and having <br>
a ".a" prefix on linux. The functions in the static library and declared <br>
as external functions using the "external <libname> name <function <br>
name>" directive. The "".a" library is copied to the same directory as <br>
the program unit before compiling and linking.<br>
<br>
However, compiling the same program on Windows always seems to result in <br>
the loader complaining that the corresponding <libname>.dll is not <br>
present, indicating that instead of linking with the static library, the <br>
program is attempting to "statically" load the correspoinding dll at <br>
initialisation time.<br>
<br>
I have tried to force it to link with the static library (e.g. using the <br>
-Xt command line switch) but no luck.<br>
<br>
Hence the question, does FPC 3.2.2 support linking with static libraries <br>
on windows?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">"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. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex" class="gmail_quote">
</blockquote></div></div></div>
</body></html>