Hello everyone!
In my low-level library
Tiny.Library, a lot of code is written in C, which is compiled into object files and linked to Delphi/FPC projects. In particular, it contains several functions that simplify and speed up working with standard types (for example, interfaces, strings, dynamic arrays). Interestingly, the internal structures of RTL are different for different versions of the compiler. Therefore, the code contains several variants for implementing the function, and only one is indicated in the header of the * .pas file. For instance:
// header:
function AStrInit(var S{: AnsiString}; const AChars: PAnsiChar; const ALength: NativeUInt; const ACodePage: Word): PAnsiChar;
// implementation:
function AStrInit; external {$ifdef EXTERNALLINKER}LIB_TINY_TYPES{$endif}
{$ifdef OBJLINKNAME}name
{$if not Defined(ANSISTRSUPPORT)}
'AStrInit_nextgen'
{$elseif not Defined(FPC)}
'AStrInit_new'
{$else .FPC}
'AStrInit_fpc'
{$ifend}
{$endif};
Now the moment has come when I need to call the final function from the C code. On the C side, I simply declare it in * .h file and try to call it at the right time:
REGISTER_DECL void* AStrInit(void* value, char8_t* chars, native_uint length, uint16_t codepage);
REGISTER_DECL void* InternalTest(void* value)
{
return AStrInit(value, (char8_t*)"Test", 4, 1251);
}
In Delphi, this construction is easily picked up - it simply sees the AStrInit function declared in Delphi and refers to it. But in FPC, in order for the object file to see the function from * .pas, the function must be marked as public, otherwise an error is generated:
Error: Undefined symbol: AStrInit
I'm trying to mark a function as public, but that doesn't help:
function AStrInit(var S{: AnsiString}; const AChars: PAnsiChar; const ALength: NativeUInt; const ACodePage: Word): PAnsiChar; {$ifdef FPC}public name 'AStrInit';{$endif}
How to fix it?