Waldek Hebisch wrote:
<snip>
Anyway, my attempt at shared libraries (I probably should call `_p_finalize' from ini.c):
I added my attempt for a dynamic library (of type MH_DYLIB) on Mac OS X. It is simply created with a call to gp:
[G5:~] adriaan% gp --compile-and-link MainUnit.pas -dynamiclib -Wl,-init,_MyDylibInit -Wl,-install_name,@executable_path/MyDylib -o MyDylib
Regards,
Adriaan van Os
----------
UNIT MyDylib; attribute( name = 'MyDylib'); {to set the external name of init routine}
INTERFACE
uses GPC;
procedure MyDylibInit; attribute( name = 'MyDylibInit'); {this routine is specified as the library's init entry point, with the -init ld switch}
{ Unlike bundle files and loadable bundle packages, dynamic libraries and frameworks on Mac OS X * are loaded automatically, rather than manually by application software * can not be unloaded (where bundles can) * can have linked-in version numbers * can have an initialization routine that is called automatically at load-time}
function MyDylibTest ( theInt1: CInteger; theInt2: CInteger): CInteger; attribute( name = 'MyDylibTest'); {just an example routine}
IMPLEMENTATION
type PCStringsPtr = ^PCStrings;
function NSGetEnviron: PCStringsPtr; external name '_NSGetEnviron'; {see the declaration in /usr/include/crt_externs.h on Mac OS X}
procedure GPC_Initialize ( theArgumentCount : CInteger; theArguments : PCStrings; theStartEnvironment : PCStrings; Options : CInteger); external name '_p_initialize'; {exported by gpc's runtime library}
procedure MyDylibUnitInit; external name 'MyDylib_init'; {re-import the compiler glue code that initializes this unit}
var gDummyArguments: array[ 0..1] of CString = ( 'MyDylib', nil);
procedure MyDylibMyInitStuff; begin {whatever} end;
procedure MyDylibInit; begin GPC_Initialize ( 1, PCStrings( @gDummyArguments), NSGetEnviron^, 0); MyDylibUnitInit; {$local W-} MyDylibMyInitStuff {$endlocal} end;
function MyDylibTest ( theInt1: CInteger; theInt2: CInteger): CInteger; begin MyDylibTest:= theInt1 + theInt2 end;
END.