[fpc-pascal] Is there a FPC symbol or define for the binary output filename?

Paul Michell Paul at MichellComputing.co.uk
Thu Apr 28 12:38:19 CEST 2016


Hello All,

I'm writing a library that needs to be used as statically linked units 
in an application and also as a stand alone dll/so for use from other 
software.  The library needs to know where its binary file is loaded on 
the host system.  The following code in the main unit's Initialization 
section does what I need for Windows and Linux, but I would like to 
avoid having to hard code the compiled binary name into the source.  Is 
there any system symbol or define I could use as a place-holder for the 
output filename?  I would like to be able to replace 'libgiq' with 
something like {$i %FPCVERSION%} so that I don't need to remember to 
edit the library when re-using it in other projects.  Also is there a 
better way to retrieve this information on Linux?

Thanks,

Paul

--------------------------------------------

{$IFDEF WINDOWS}
DataFolder := 
IncludeTrailingPathDelimiter(ExtractFilePath(GetModuleName(HInstance)));
{$ELSE}
If IsLibrary Then
   Begin
     AssignFile(DataFile, '/proc/self/maps');
     Try
       Reset(DataFile);
       While Not EOF(DataFile) Do
         Begin
           readln(DataFile, MapText);
           If Pos('libgiq', MapText)<>0 Then
             Begin
               DataFolder := ExtractFilePath(Copy(MapText, 
LastDelimiter(' ',MapText)+1, Length(MapText)));
               Exit;
             End;
         End;
       CloseFile(DataFile);
     Except
       On E: EInOutError Do
         writeln('File handling error: ', E.Message);
     End;
   End
Else
   DataFolder := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
{$ENDIF}



More information about the fpc-pascal mailing list