I'm using multiple statically-linked C libraries (in separate packages) in the same project. For maximum compatibility (i.e. to avoid having to install yet another VC++ redistributable) I'm linking against
msvcrt.dll on Windows. It's a legacy component, but for my purposes it's sufficient.
There is one caveat, however - it doesn't define
atexit, which is used by the C library code. There's the Microsoft equivalent
_onexit, so it'd be trivial to just declare a shim function:
function onexit(func: pcvoid): cint; cdecl; external name '_onexit';
function atexit(func: pcvoid): cint; cdecl; public name 'atexit';
begin
Result := onexit(func);
end;
But then the question becomes where to place this definition:
- Within each project: Inelegant, would like to avoid such boilerplate
- Within each package: Only works if exactly one such package is used in a project, because otherwise the atexit symbol is defined multiple times and the linker complains
I've also tried marking the
atexit symbol as weak by implementing it in C with GCC's
__attribute__((weak)), but then FPC's internal linker aborts because it can't recognize the symbol's type.
So far it seems like the only viable option is to create a static library (e.g.
libmsvcrt_shim.a) containing the
atexit definition and link against that, because I know from prior experience that FPC aggressively deduplicates
{$linklib} directives.
Any other suggestions?
