Weak Linking on Linux lazarus / 32-Linux ---------------------------------------------------------------------- Kevan S. Hashemi · 2020-11-11 18:48 Dear All, I'm compiling a dynamic library (DLL) with FPC. At compile time, I have available all routines the DLL references external to itself. At run-time I sometimes have all these routines available, in which case the DLL runs just fine on Linux, Windows, and MacOS (different DLL for each OS). I sometimes do not have all these routines available, but that should be okay because in those cases, the DLL won't call any unresolved external routines. On MacOS and Windows, the DLL runs just fine, because of what I believe is called "weak linking". On Linux, the DLL returns an "undefined symbol" error and fails to load. I need weak linking on Linux. Looking at this page. https://wiki.freepascal.org/FPC_HowToDo#Weak_linking it appears that weak linking for Linux is possible with an "external assembler". I am hoping for an FPC equivalent to the GCC "__attribute__((weak))" directive, so that the DLL with ignore the unresolved references at run-time. But if I must mess around in the assembler, I'd like to give that a try, if instructions exist. If example code would help, I'll construct three example objects that illustrate the problem. Best Wishes, Kevan ---------------------------------------------------------------------- MarkMLl · 2020-11-11 19:23 I've never played with that, and I'd be a bit wary looking at how old those additions to the page are (i.e. without more recent comment or updates). I've done a lot of explicit dynamic loading, and a fair amount of explicit negotiation relating to plugin versions etc., https://forum.l azarus.freepascal.org/index.php/topic,49502.msg383415.html#msg383415 is relevant but there's a great deal of "boilerplate" which has to be written to get things to work. MarkMLl ---------------------------------------------------------------------- marcov · 2020-11-11 20:28 There is a weakexternal directive, Quotefunction objc_getProtocol(name:pchar): pobjc_protocol; cdecl; weakexternal libname; ---------------------------------------------------------------------- MarkMLl · 2020-11-11 21:31 Quote from: marcov on November 11, 2020, 09:28:12 pmThere is a weakexternal directive, Quote Thanks for that. What happens if it's not satisfied? MarkMLl ---------------------------------------------------------------------- marcov · 2020-11-11 21:59 I assume it is nil then. It could be that only referencing can be done by directive, and _defining_ a weak symbol only works in external assembler. The usage seems to be mostly OS X though (grep for it in rtl/inc) and some startup code like riscv64/si_c.inc:  libc_init_proc: TProcedure; weakexternal name '_init'; riscv64/si_c.inc:  libc_fini_proc: TProcedure; weakexternal name '_fini'; xtensa/si_c.inc:  libc_init_proc: TProcedure; weakexternal name '_init'; xtensa/si_c.inc:  libc_fini_proc: TProcedure; weakexternal name '_fini'; ---------------------------------------------------------------------- Kevan S. Hashemi · 2020-11-11 22:19 Hi Marcov, > weakexternal libname; Sweet! That works perfectly. For some reason, weak external is the default on MacOS and Windows. Now it is explicit in all platforms. I search on-line for "Free Pascal Compiler weak external directive" and come up with nothing. Where should I have looked for documentation for this directive? Thank you, Kevan ---------------------------------------------------------------------- marcov · 2020-11-11 22:29 Afaik it is undocumented