Recent

Author Topic: dynamic library not load when you add indylaz requirement (in library)  (Read 923 times)

uganof

  • New Member
  • *
  • Posts: 10
Development environment:

macos Ventura 13.2.1
lazarus 2.2.4
indylaz 10.6.2.4089

Simple library demo test:

Code: [Select]
library project1;

{$mode Delphi}{$H+}
{$IFDEF MSWINDOWS}
  {$calling stdcall}
{$ENDIF}
{$IFDEF Unix}
{$calling cdecl}
{$ENDIF}
{$IFDEF Darwin}
{$calling cdecl}
{$ENDIF}

{$R *.res}

uses
  interfaces, Classes, indylaz;

function substr(CString: PChar; FromPos, ToPos: Longint): PChar;
var
  Length: Integer;
begin
  Length := StrLen(CString);
  SubStr := CString + Length;
  if (FromPos > 0) and (ToPos >= FromPos) then
  begin
    if Length >= FromPos then
      SubStr := CString + FromPos;
    if Length > ToPos then
    CString[ToPos+1] := #0;
  end;
end;

exports
  substr;
end.     

Simple program for test:

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}
{$IFDEF MSWINDOWS}
  {$calling stdcall}
{$ENDIF}
{$IFDEF Unix}
{$calling cdecl}
{$ENDIF}
{$IFDEF Darwin}
{$calling cdecl}
{$ENDIF}
{$LinkLib project1}

interface

uses
  dynlibs, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;

type
  { TForm1 }
  TForm1 = class(TForm)
    Button2: TButton;
    Memo1: TMemo;
    procedure Button2Click(Sender: TObject);
  private
    apri : procedure;
  public
  end;

var
  Form1: TForm1;

function substr(CString: PChar; FromPos, ToPos: Longint): PChar; cdecl; external;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button2Click(Sender: TObject);
var
  a : array [0..100] of char;
  path : string;
begin
  a := 'ciao a tutti';
  Memo1.Lines.Add(substr(a, 2, 4));
end;

end.   

With dependency on indylaz, it exits with errors:

./testlib_lazarus
objc[1664]: Class TCocoaTimerObject is implemented in both /Users/ugoboccardi/lazarus/test library/libproject1.dylib (0x107889640) and /Users/ugoboccardi/lazarus/test library/testlib_lazarus (0x10566d738). One of the two will be used. Which one is undefined.
objc[1664]: Class TAppDelegate is implemented in both /Users/ugoboccardi/lazarus/test library/libproject1.dylib (0x107889690) and /Users/ugoboccardi/lazarus/test library/testlib_lazarus (0x10566d788). One of the two will be used. Which one is undefined.
objc[1664]: Class TCocoaApplication is implemented in both /Users/ugoboccardi/lazarus/test library/libproject1.dylib (0x1078896e0) and /Users/ugoboccardi/lazarus/test library/testlib_lazarus (0x10566d7d8). One of the two will be used. Which one is undefined.
objc[1664]: Class TLCLEventMessage is implemented in both /Users/ugoboccardi/lazarus/test library/libproject1.dylib (0x107889730) and /Users/ugoboccardi/lazarus/test library/testlib_lazarus (0x10566d828). One of the two will be used. Which one is undefined.
objc[1664]: Class TCocoaAlertCancelAccessoryView is implemented in both /Users/ugoboccardi/lazarus/test library/libproject1.dylib (0x107889780) and /Users/ugoboccardi/lazarus/test library/testlib_lazarus (0x10566d878). One of the two will be used. Which one is undefined.

...

[FORMS.PP] ExceptionOccurred
  Sender=EStackOverflow
  Exception=Stack overflow
  Stack trace:
  $00000001070D69E0
Exception at 00000001070D69E0: EStackOverflow:
Stack overflow.

Without inserting the dependency on indylaz in the library, it works.

The same code in Lazarus on Windows or Linux works perfectly.

Does anyone have any idea what can be done?
« Last Edit: February 24, 2023, 04:49:19 pm by uganof »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2083
  • Fifty shades of code.
    • Delphi & FreePascal
Re: dynamic library not load when you add indylaz requirement (in library)
« Reply #1 on: February 24, 2023, 11:04:07 am »
Welcome to forum!
Please use the [ # ] button and put your code within the [ code ] your code [ /code ] tags.

My belly tells me, here you have an error.
Code: Pascal  [Select][+][-]
  1. function substr(CString: PChar; FromPos, ToPos: Longint): PChar; cdecl; external;
Should be
Code: Pascal  [Select][+][-]
  1. function substr(CString: PChar; FromPos, ToPos: Longint): PChar; external;
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

uganof

  • New Member
  • *
  • Posts: 10
Re: dynamic library not load when you add indylaz requirement (in library)
« Reply #2 on: February 24, 2023, 05:00:19 pm »
Quote
Welcome to forum!

thanks!

Quote
Please use the [ # ] button and put your code within the [ code ] your code [ /code ] tags.

now it is more beautiful  :D

Quote
My belly tells me, here you have an error.

unfortunately that's not the problem, cdecl is normal on linux or macos. Rather, it appears that the indylaz package links to a library it shouldn't

uganof

  • New Member
  • *
  • Posts: 10
I dug deeper and realized that the problem is in the initialization section of the indy library, cocoa class duplication messages have nothing to do with it.

In the source I eliminated the indylaz unit and put the idglobal to make troubleshooting easier

Code: Pascal  [Select][+][-]
  1. library project1;
  2.  
  3. {$mode Delphi}{$H+}
  4. {$IFDEF MSWINDOWS}
  5.   {$calling stdcall}
  6. {$ENDIF}
  7. {$IFDEF Unix}
  8. {$calling cdecl}
  9. {$ENDIF}
  10. {$IFDEF Darwin}
  11. {$calling cdecl}
  12. {$ENDIF}
  13.  
  14. {$R *.res}
  15.  
  16. uses
  17.   interfaces, Classes, IdGlobal;
  18.  
  19. function substr(CString: PChar; FromPos, ToPos: Longint): PChar;
  20. var
  21.   Length: Integer;
  22. begin
  23.   Length := StrLen(CString);
  24.   SubStr := CString + Length;
  25.   if (FromPos > 0) and (ToPos >= FromPos) then
  26.   begin
  27.     if Length >= FromPos then
  28.       SubStr := CString + FromPos;
  29.     if Length > ToPos then
  30.     CString[ToPos+1] := #0;
  31.   end;
  32. end;
  33.  
  34. exports
  35.   substr;
  36. end.    

The result was the same, with the same errors.

But, if in IdGlobal I delete the intialization section all works!

it is not a problem of the initialization section because I use it in other libraries and it works correctly but something seems to be activated in the Indy library which makes it unusable.

Does anyone have an idea what it could be?


 

TinyPortal © 2005-2018