[Solved] getprocaddress lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- RednosePete · 2018-02-23 10:42 I try to use a procedure from dylib (coded in Fortran and compiled with ifort) in a 64-bit console app. I can make it work when a compile a test program with ppcx64; dylib is succesfully loaded and GetProcAddress find the procedure. However, when I embed the same code in Lazarus-project and build it with lazbuild, dylib is loaded but GetProcAddress returns nil. var  Handle1 : TLibHandle;  MyProcedure : TMyProcedure;  ptr1 : Pointer; begin   Handle1 := TLoadLibrary (PChar('libTest.dylib'));   if Handle1 <> nil then   begin    ptr1 := GetProcAddress(Handle1,PChar('functioname'));    if ptr1 <> nil then     writeln('Function address found');   else     writeln('Failed ...');   end; end; Any ideas? Are there some compiler options either on ppcx64 or Lazarus that should take note on? Should I drop lazbuild and build the project with ppcx64? ---------------------------------------------------------------------- Phemtik · 2018-02-23 11:00 Why you use a PChar cast  for LoadLibary and GetProcAdress? Both functions want a normal String. ---------------------------------------------------------------------- RednosePete · 2018-02-23 11:20 Quote from: Phemtik on February 23, 2018, 12:00:46 pmWhy you use a PChar cast  for LoadLibary and GetProcAdress? Both functions want a normal String. Ok, thanks. I removed PChar and the same result; ppcx64  produces app that works, Lazarus (via lazbuild) not. ---------------------------------------------------------------------- rvk · 2018-02-23 11:27 I see much more problems with that code. Where is the end for the begin/end block when Handle1 <> nil. When I try to compile this... where (and what) is TLoadLibrary? TLibHandle is a DWord (for me) so you can't check that against nil (which is a pointer). Check it against nilhandle. Is "functioname" the real functioname? (note absence of n) Is this better? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  Handle1: TLibHandle;  ptr1: Pointer;begin  Handle1 := LoadLibrary('libTest.dylib');  if Handle1 <> nilhandle then  begin    ptr1 := GetProcAddress(Handle1, 'functioname');    if ptr1 <> nil then      writeln('Function address found');  end  else  begin    writeln('Failed ...');  end;end; PLEASE DON'T POST JUST TYPED TEXT. Use real code you have in your project !! One typo is easily made and we can't see your real code. (and use the #-code button to mark code) ---------------------------------------------------------------------- RednosePete · 2018-02-23 13:14 Quote from: rvk on February 23, 2018, 12:27:10 pmPLEASE DON'T POST JUST TYPED TEXT. Use real code you have in your project !! (and use the #-code button to mark code) Sorry about my newbie mistakes, and yes, your version of code looks better (lesson learned   ). As you already concluded, I didn't copy-paste the actual code, hence the typos. The original code in my Lazarus-project is a bit longish. The dylib my app loads is written in Fortran and compiled for 64-bit OSX. I can use the function successfully when compiling a simple test program with ppcx64 or when using early (static) binding in Lazarus. The problem is GetProcAddress when compiled via Lazarus target OS being "Default" and target CPU being x86_64. In my case, I use lazbuild with , but that shouldn't make any difference or does it? So far, I've compared a large Lazarus project vs. a simple ppcx64 compiled console application. The former is built with: lazbuild -B MApp.lpi --ws=cocoa --cpu=x86_64 --os=darwin --compiler=/usr/local/lib/fpc/3.0.4/ppcx64 and latter: ppcx64 -MDelphi veri2.pas My next step is testing GeProcAddress with a simple Lazarus-console application. I suppose that calling convention shouldn't be an issue in 64-bit applications? ---------------------------------------------------------------------- rvk · 2018-02-23 13:25 Quote from: RednosePete on February 23, 2018, 02:14:01 pmAs you already concluded, I didn't copy-paste the actual code, hence the typos. The original code in my Lazarus-project is a bit longish. ... My next step is testing GeProcAddress with a simple Lazarus-console application. Yes, when you run into something it would be best to create a small test-project where you try to accomplish the same. If that fails you can copy paste the correct compilable code so there are no possible typos (which we will otherwise find and think that's the issue). Quote from: RednosePete on February 23, 2018, 02:14:01 pmppcx64 -MDelphi veri2.pas If you switch to Delphi mode you should also put Delphi mode in your lazbuild. Better is to add the Delphi mode in your sources. So add something like this at the top Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$IFDEF FPC}    {$MODE DELPHI}  {$ENDIF FPC} ---------------------------------------------------------------------- RednosePete · 2018-02-23 15:21 Quote from: rvk on February 23, 2018, 02:25:23 pmIf you switch to Delphi mode you should also put Delphi mode in your lazbuild. Better is to add the Delphi mode in your sources. So add something like this at the top Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$IFDEF FPC}    {$MODE DELPHI}  {$ENDIF FPC} Yup, that I had already in my Lazarus-project. It is nice to have advice on those desperate moments when you have lost the path; thanks ... I'll be back after experimenting with a simple Lazarus app. ---------------------------------------------------------------------- RednosePete · 2018-02-24 16:58 This works when command-line compiling with ppcx64, but as a Lazarus app, it won't find the dylib. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMyApplication.DoRun;var  ErrorMsg: String;   prm1                    : single;   ptr1                    : Pointer;   Handle1               : TLibHandle;   GetFigm                 : TGetFigm;   FIGM                  : string = 'libvol.dylib';   MYFUN                   : string = 'figm';begin     writeln('Trying to load');     Handle1 := LoadLibrary(FIGM);     if Handle1 <> nilhandle then     begin        writeln('handle 1 ok, looking after ',MYFUN);        ptr1 := GetProcAddress(Handle1, MYFUN);        if ptr1 <> nil then           writeln(MYFUN,' found')        else          writeln(MYFUN,' not found');     end     else         writeln(FIGM,' not loaded');  Terminate;end; My newbie difficulties may arise not from the code itself but my incomplete understanding of search paths when loading libraries run- time. During my previous attempts, the Lazarus project loaded a different (and faulty) version of dylib while command-line compiled version used the current directory as default path when loading dylib with dynlibs.LoadLibrary. Now that I do have only one (and correct) version of the dylib, and it is located in the same folder with the executable, Lazarus app can't find the dylib at all; Code: [Select]Trying to load libvol.dylib not loadedAnd the same code compiled with ppcx64 results; Code: [Select]Trying to load handle 1 ok, looking after figm figm found How do you define the location where Lazarus application is expecting to find a dylib when late-binding? In my case the test program is a simple console application that I run in a terminal. Are there some project options? What is the default location in Lazarus app? Sorry for beginner questions; my only excuse is that I am a beginner at OSX. ---------------------------------------------------------------------- Phil · 2018-02-24 17:06 Quote from: RednosePete on February 24, 2018, 05:58:22 pmHow do you define the location where Lazarus application is expecting to find a dylib when late-binding? In my case the test program is a simple console application that I run in a terminal. Are there some project options? What is the default location in Lazarus app? Sorry for beginner questions; my only excuse is that I am a beginner at OSX. Per FPC documentation, be sure to only pass a complete path to LoadLibrary. In your example code, you're only passing the file name of the library. https://www.freepascal.org/docs-html/rtl/dynlibs/loadlibrary.html In an app bundle, libraries are placed in the Frameworks folder. You can get this location with: NSBundle.mainBundle.sharedFrameworksURL.UTF8String With a console app, if the .dylib is in the same folder as the executable, use ParamStr(0) and extract the path. Edit: oops, sharedFrameworksPath, not sharedFrameworksURL. More here: https://developer.apple.com/documentation/foundation/nsbundle?language =objc ---------------------------------------------------------------------- RednosePete · 2018-02-24 18:22 I tried both './libvol.dylib' and the full path given by pwd in terminal. Neither did help, Lazarus-built app won't find the dylib while compiling with ppcx64 (no command line options!) results as a working application. It must be some option in Lazarus project settings? I suppose that the compiler is in both cases (with or without Lazarus) actually the same. ---------------------------------------------------------------------- Phil · 2018-02-24 18:28 Quote from: RednosePete on February 24, 2018, 07:22:22 pmI tried both './libvol.dylib' and the full path given by pwd in terminal. Neither did help, Lazarus-built app won't find the dylib while compiling with ppcx64 (no command line options!) results as a working application. It must be some option in Lazarus project settings? I suppose that the compiler is in both cases (with or without Lazarus) actually the same. This has nothing to do with Lazarus per se since Lazarus has no knowledge of or support for the macOS .app bundle structure, other than creating an incorrect .app bundle the first time you run the app (symlink pointing to executable outside of bundle - wrong, bad idea, design error, something not done by any other IDE on Earth). You're doing something else wrong. Post a simple example (project source files, etc.). ---------------------------------------------------------------------- RednosePete · 2018-02-24 18:52 Project1.pas Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$mode objfpc}{$H+} uses   dateutils,dynlibs,  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, SysUtils, CustApp type   { TMyApplication }   TMyApplication = class(TCustomApplication)  protected    procedure DoRun; override;  public    constructor Create(TheOwner: TComponent); override;    destructor Destroy; override;  end; TGetFigm = function(var inval:single):single; stdcall; { TMyApplication } procedure TMyApplication.DoRun;var  ErrorMsg: String;   prm1                    : single;   ptr1                    : Pointer;   Handle1               : TLibHandle;   GetFigm                 : TGetFigm;   FIGM                  : string = 'libvol.dylib';   MYFUN                   : string = 'figm';begin     writeln('Trying to load');     writeln(ExtractFilePath(ParamStr(0)));     Handle1 := LoadLibrary(FIGM);     if Handle1 <> nilhandle then     begin        writeln('handle 1 ok, looking after ',MYFUN);        ptr1 := GetProcAddress(Handle1, MYFUN);        if ptr1 <> nil then           writeln(MYFUN,' found')        else          writeln(MYFUN,' not found');     end     else         writeln(FIGM,' not loaded');  Terminate;end; constructor TMyApplication.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);  StopOnException:=True;end; destructor TMyApplication.Destroy;begin  inherited Destroy;end;  var  Application: TMyApplication;begin  Application:=TMyApplication.Create(nil);  Application.Title:='My Application';  Application.Run;  Application.Free;end.  Project1.lpi Code: XML  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i                                                             <UseAppBundle Value="False"/>    <ResourceType Value="res"/>    </General>    <BuildModes Count="1">    <Item1 Name="Default" Default="True"/>    </BuildModes>    <PublishOptions>      <Version Value="2"/>      <DestinationDirectory Value="/Users/myusername/Documents/TestCodes/LTest/Test"/>    </PublishOptions>    <RunParams>      <local>        <FormatVersion Value="1"/>      </local>    </RunParams>    <Units Count="1">      <Unit0>        <Filename Value="Project1.pas"/>        <IsPartOfProject Value="True"/>      </Unit0>    </Units>  </ProjectOptions>  <CompilerOptions>    <Version Value="11"/>    <Target>      <Filename Value="Project1"/>    </Target>    <SearchPaths>      <IncludeFiles Value="$(ProjOutDir)"/>      <Libraries Value="."/>      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>    </SearchPaths>    <CodeGeneration>      <TargetCPU Value="x86_64"/>    </CodeGeneration>  </CompilerOptions>  <Debugging>    <Exceptions Count="3">      <Item1>        <Name Value="EAbort"/>      </Item1>    <Item2>        <Name Value="ECodetoolError"/>      </Item2>      <Item3>        <Name Value="EFOpenError"/>      </Item3>    </Exceptions>  </Debugging></CONFIG>  Two binaries, the first (finds dylib) compiled by: ppcx64 Project1.pas the second (dylib not found): lazbuild Project1.lpi libvol.dylib is in the same folder where Project1.pas, Project1.lpi and the respective executable Project1 are. Haven't tried Application bundle. ---------------------------------------------------------------------- rvk · 2018-02-24 18:59 Really strange. Are both executables the same size? (You did not give a complete path but I guess if it's not needed for one, it's also not need for the other) ---------------------------------------------------------------------- Phil · 2018-02-24 19:10 Quote from: RednosePete on February 24, 2018, 07:52:12 pmHaven't tried Application bundle. Just tested with the libndfd.dylib library that can be built from this example: https://macpgmr.github.io/MacXPlatform/PascalDynLibs_2.html Created Frameworks folder in test app's bundle and copied libndfd.dylib to it. Here's my complete code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type TNdfdGetLibVersion = procedure(VerBuf    : PAnsiChar;                                  VerBufLen : cuint32); cdecl; procedure TForm1.Button1Click(Sender: TObject);var  NdfdHandle : TLibHandle;  VersAddr   : TNdfdGetLibVersion;  Buffer     : array [0..100] of AnsiChar;begin  NdfdHandle := LoadLibrary(NSBundle.MainBundle.privateFrameworksPath.UTF8String +                          '/libndfd.dylib');  if NdfdHandle = 0 then    begin    WriteLn('Unable to load lib');    Exit;    end;  VersAddr := TNdfdGetLibVersion(GetProcAddress(NdfdHandle, 'NdfdGetLibVersion'));  VersAddr(Buffer, SizeOf(Buffer));  WriteLn(string(Buffer));end;  When run in debugger (lldb) it prints "1.0.4" to console. ---------------------------------------------------------------------- RednosePete · 2018-02-24 19:13 Quote from: rvk on February 24, 2018, 07:59:43 pmReally strange. Are both executables the same size? (You did not give a complete path but I guess if it's not needed for one, it's also not need for the other) The executables are of different size, ppcx64 produces a slightly bigger application: the first one: 2021620 Feb 24 21:07 Project1 the second one: 1976020 Feb 24 21:08 Project1 Building from Lazarus IDE gives the same size of executable as lazbuild, so at least there is some logic ... ---------------------------------------------------------------------- RednosePete · 2018-02-24 19:18 Quote from: Phil on February 24, 2018, 08:10:01 pmQuote from: RednosePete on February 24, 2018, 07:52:12 pmHaven't tried Application bundle. Just tested with the libndfd.dylib library that can be built from this example: https://macpgmr.github.io/MacXPlatform/PascalDynLibs_2.html Created Frameworks folder in test app's bundle and copied libndfd.dylib to it. When run in debugger (lldb) it prints "1.0.4" to console. Ok, thanks. I will try that (bundle). ---------------------------------------------------------------------- rvk · 2018-02-24 19:23 I see in Lazarus itself (under Project > Project Options) that for running and debugging the Application bundle is used. (no idea what that actually means for a standalone compiled application) There is a button at the bottom of the options, Show Options. You could try ppcx64 with those options and see if it also fails. If it does then you can strip the options to see which one causes it. ---------------------------------------------------------------------- RednosePete · 2018-02-24 19:59 Quote from: rvk on February 24, 2018, 08:23:28 pmI see in Lazarus itself (under Project > Project Options) that for running and debugging the Application bundle is used. (no idea what that actually means for a standalone compiled application) There is a button at the bottom of the options, Show Options. You could try ppcx64 with those options and see if it also fails. If it does then you can strip the options to see which one causes it. Thanks, I'll give it a try. ---------------------------------------------------------------------- RednosePete · 2018-02-25 06:20 Quote from: RednosePete on February 24, 2018, 08:59:01 pmQuote from: rvk on February 24, 2018, 08:23:28 pmI see in Lazarus itself (under Project > Project Options) that for running and debugging the Application bundle is used. (no idea what that actually means for a standalone compiled application) There is a button at the bottom of the options, Show Options. You could try ppcx64 with those options and see if it also fails. If it does then you can strip the options to see which one causes it. Thanks, I'll give it a try. It wasn't due to compiler options; adding them to ppcx64 didn't change the behaviour of the executable. ---------------------------------------------------------------------- RednosePete · 2018-02-25 08:12 Yet, dylibs in e.g. /usr/lib are "visible" (can be loaded) perfectly well also with an app compiled via Lazarus. I don't have write- permission to /usr/lib and nor do I have admin-rights. I tried to add my dylib path to PATH, DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH but no success. This seems to be more OSX- than Lazarus-issue. ---------------------------------------------------------------------- RednosePete · 2018-02-25 09:29 I getting more and more confused ... My current code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMyApplication.DoRun;var  ErrorMsg: String;   prm1                    : single;   ptr1                    : Pointer;   Handle1               : TLibHandle;   GetFigm                 : TGetFigm;   opath                 : string;   FIGM                    : string = 'libvol.dylib';   MYFUN                   : string = 'figm';begin     writeln('Trying to load');     writeln('CurrentDir=',GetCurrentDir);     FIGM := GetCurrentDir+'/'+FIGM;     if FileExists(FIGM) then writeln(FIGM,' exists');     Handle1 := LoadLibrary(FIGM);     if Handle1 <> nilhandle then     begin        writeln('handle 1 ok, looking for ',MYFUN);        ptr1 := GetProcAddress(Handle1, MYFUN);      if ptr1 <> nil then           writeln(MYFUN,' found')        else          writeln(MYFUN,' not found');         FreeLibrary(Handle1);     end     else         writeln(FIGM,' not loaded');  Terminate;end; Compiled via Lazarus or lazbuild, this is how it executes: Trying to load CurrentDir=/Users/myusername/Documents/TestCodes/LTest /Users/myusername/Documents/TestCodes/LTest/libvol.dylib exists /Users/myusername/Documents/TestCodes/LTest/libvol.dylib not loaded And the same application compiled with ppcx64: Trying to load CurrentDir=/Users/myusername/Documents/TestCodes/LTest /Users/myusername/Documents/TestCodes/LTest/libvol.dylib exists handle 1 ok, looking for figm figm found ---------------------------------------------------------------------- rvk · 2018-02-25 10:02 What does getloaderrorstr give back after the failed loading of that library? https://www.freepascal.org/docs-html/rtl/dynlibs/getloaderrorstr.html It should be the first system call after loadlibrary so do s := getloaderrorstr; directly after it and then output s. (Not sure it's needed under macos but better to make sure) ---------------------------------------------------------------------- RednosePete · 2018-02-25 10:36 Quote from: rvk on February 25, 2018, 11:02:40 amWhat does getloaderrorstr give back after the failed loading of that library? https://www.freepascal.org/docs-html/rtl/dynlibs/getloaderrorstr.html It should be the first system call after loadlibrary so do s := getloaderrorstr; directly after it and then output s. (Not sure it's needed under macos but better to make sure) Finally, we are getting closer: dlopen(/Users/myusername/Documents/TestCodes/LTest/libvol.dylib, 1): no suitable image found.  Did find:    ./libvol.dylib: mach-o, but wrong architecture and file libvol.dylib gives: file libvol.dylib libvol.dylib: Mach-O 64-bit dynamically linked shared library x86_64 My next guess is to compile a 32-bit -version of libvol.dylib and "lipo" then 32bit and 64bit dylibs together. Could it be so easy that LoadLibrary in Lazarus can load only 32-bit libraries? ---------------------------------------------------------------------- RednosePete · 2018-02-25 11:06 Okay, I think we (!!! thank you rvk and Phil) probably solved it; lipo -create libvol32.dylib libvol64.dylib -output libvol.dylib and file libvol.dylib returns: libvol.dylib: Mach-O universal binary with 2 architectures libvol.dylib (for architecture i386):   Mach-O dynamically linked shared library i386 libvol.dylib (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library x86_64 Now both versions (ppcx64 and Lazarus) open the 2-architecture -dylib and find the function in it. I haven't yet tried the function, so there might be still a chance that I get a wrong handle and incorrect (=32bit) function address (I have no previous experience on using double-architecture libraries). ---------------------------------------------------------------------- rvk · 2018-02-25 11:11 That would mean your lazbuild project is still i386, doesn't it? If ppcx64 is capable of producing code for loadlibrary which can load x64 libraries, lazbuild should be too. So my guess is that you lazbuild is somehow still stuck on i386. Can you check the architecture of your lazbuild project using the file command? ---------------------------------------------------------------------- RednosePete · 2018-02-25 11:34 Quote from: rvk on February 25, 2018, 12:11:34 pmThat would mean your lazbuild project is still i386, doesn't it? If ppcx64 is capable of producing code for loadlibrary which can load x64 libraries, lazbuild should be too. So my guess is that you lazbuild is somehow still stuck on i386. Can you check the architecture of your lazbuild project using the file command? You are absolutely correct: file Project1 gave: Project1: Mach-O executable i386 After adding the correct options to lazbuilt: lazbuild -B Project.lpi --ws=cocoa --cpu=x86_64 --os=darwin --compiler=/usr/local/lib/fpc/3.0.4/ppcx64 and now file Project1 gives: Project1: Mach-O 64-bit executable x86_64 and 64bit 1-architecture libvol.dylib is found! Conclusion: although project options have <TargetCPU Value="x86_64"/> I must specify target architecture as lazbuild's command line option Thanks for help!! This case is so far solved. My next step is get what I've learned and go back to the original (large) project. If I can get dylibs correctly loaded there, this case is finally solved. ---------------------------------------------------------------------- RednosePete · 2018-02-25 12:04 An update: even though the target CPU family in project options is x86_64, building via Lazarus produces 32-bit app if Compiler Command is "$(CompPath)". When I change it to "/usr/local/lib/fpc/3.0.4/ppcx64", I get a 64-bit app. Perhaps this is something I should have known in the first place, isn't it. Finally; the reason my application was unable to load a 64-bit dylib was that the application never was built for 64-bit platform. It took a bit too long for me to figure that out, and without your help I pretty sure would be still lost and confused. Why in earth I didn't check the architecture of my executables until rvk told me to do so . I probably have to change my username to RedFacePete. ---------------------------------------------------------------------- rvk · 2018-02-25 12:19 Quote from: RednosePete on February 25, 2018, 01:04:59 pmAn update: even though the target CPU family in project options is x86_64, building produces 32-bit app if Compiler Command is "$(CompPath)". When I change it to "/usr/local/lib/fpc/3.0.4/ppcx64", I get a 64-bit app. Perhaps this is something I should have known in the first place, isn't it.Well, I think choosing x86_64 as Target CPU should/could have done that automatically for you. Although choosing a CPU target in the option, which the $(CompPath) compiler does not support, gets me a warning when pressing OK. Is this not the case in the Mac version? QuoteCompiler "C:\dev\fpc\bin\i386-win32\fpc.exe" does not support target x86_64-win32 QuoteFinally; the reason my application was unable to load a 64-bit dylib was that the application never was built for 64-bit platform. It took a bit too long to figure that out, and without your help I pretty sure would be still lost and confused.Yeah, I should have asked after the first post to check the arch with file But I also just assumed a 64 bit version was created. Glad it works now. ---------------------------------------------------------------------- ChPr · 2024-09-06 08:49 Quote from: rvk on February 25, 2018, 12:11:34 pm ... Can you check the architecture of your lazbuild project using the file command? Hello everybody, I have much the same problem. On MacOS, I want to link a library to my program. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function InstalleLib(FchLib: String): Boolean;var  Fch: String;  Menu, SousMenu: TMenuItem;  i, N, NbM, NoM, PosM: Integer;begin  Fch:= DirEXE;  Fch:= IncludeTrailingPathDelimiter(Fch+FchLib);{$IFDEF WINDOWS}  FchLib:= Fch+FchLib+'.dll';{$ENDIF}{$IFDEF LINUX}  FchLib:= Fch+'lib'+LowerCase(FchLib)+'.so';{$ENDIF}{$IFDEF DARWIN}  FchLib:= Fch+'lib'+LowerCase(FchLib)+'.dylib';{$ENDIF}  HndLib:= LoadLibrary(PChar(FchLib));  if HndLib <> 0 then  begin    Pointer(AddMenu):= GetProcAddress(HndLib, PChar('AddMenu'));    Pointer(EnvoiDirLib):= GetProcAddress(HndLib, 'EnvoiDirLib');    Pointer(ArticleEnBdD):= GetProcAddress(HndLib, 'ArticleEnBdD');    Pointer(MajStock):= GetProcAddress(HndLib, 'MajStock');    if (Pointer(AddMenu) <> nil)    and (Pointer(EnvoiDirLib) <> nil)    and (Pointer(ArticleEnBdD) <> nil)    and (Pointer(MajStock) <> nil) then    begin      EnvoiDirLib(PChar(Fch));         {Envoie le Dir de la BdD : .../Articles}      Menu:= TMenuItem.Create(Base.MenuPrinc);      PosM:= 1;                      {Position d'insertion des menus de la Lib}      N:= 0;{AddMenu(0) retourne le nom du menu à ajouter et le Nb de Sousmenu}      Menu.Caption:= String(AddMenu(N));              {Récupère le nom du menu}      SetLength(ListSousMenu, Length(ListSousMenu)+N);      NbM:= Base.MenuPrinc.Items.Count;          {Nombre de menus prédéfinis}      Base.MenuPrinc.Items.Insert(PosM, Menu);              {Insertion du menu}      for i:= 1 to N do                             {Création des N sous-menus}      begin        SousMenu:= TMenuItem.Create(Base.MenuPrinc);        ListSousMenu[High(ListSousMenu)-N+i]:= SousMenu;        NoM:= i;      SousMenu.ImageIndex:= i+11;   {11 = dernier indice des des menus fixes}        SousMenu.Caption:= string(AddMenu(NoM));        SousMenu.Enabled:= True;        SousMenu.Tag:= i;          {Mémo de l'indice du sous-menu dans son Tag}        SousMenu.OnClick:= @Base.ClickMenu;  {Affectation de la fonction Click}        Base.MenuPrinc.Items[PosM].Add(SousMenu);       {Installe le sous- menu}      end;      LibOK:= True;      Result:= True;    end    else      LibOK:= False;  end  else    LibOk:= False;  Result:= LibOK;end;  I've done what was recommended above, i.e. not to leave a default value, I've put, both in the library parameters and in those of the program :     Destination OS: Darwin    CPU family: X86-64    Target processor: ATHLON64The library is found and, although the following test : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i chpr@Mac- de-chpr Facturation % file FactDevEIFactDevEI: Mach-O 64-bit executable x86_64shows that my architecture is indeed X86_64, "getProcAddress" always returns “nil”. An idea of the problem ? Sincerely. Pierre.