Hi,
I cranked up a simple dylib test application after trying with no success to convert a slightly more complicated test app and dylib. I was using Trunk/Trunk, but have now gone back to 2.0.0RC3 FWIW. On the plus side, I think I turned on verbose logging on the 2.0.TC3 version and I suspect that is showing what's missing.
The simple application worked in i386/Carbon, but now does not in x86_64/Cocoa. It's the same test code I mentioned in this post:
http://forum.lazarus-ide.org/index.php?topic=43925.msg308247#msg308247 posted later, but the link error I'm getting when trying to build the simple dylib is cannot find:
/usr/lib/dylib1.10.5.o
I have absolutely no idea what this file is and I can confirm I certainly don't have it. If I had to guess I'd say it ha something to do with macOS (but 10.5 was a millennia ago so probably not). I'm currently using 10.14.
And if I set
{$mode delphi} Then this file cannot be found:
/usr/lib/crt1.10.5.o
Does anyone have an idea of what dylib1.10.5.o is and how I might either get a copy of fix it so that the system doesn't need it?
The code is below (and it did work with i386/carbon). If it's TL;DR then fine, I just need some help with dylib1.10.5.o and/or crt1.10.5.o?
The DYLIB: This is the new direct call: DYLIB / DLL using FMX.Forms and FMX.Dialogs');
{$IFDEF WINDOWS}
sType := 'Windows DLL';
{$ENDIF WINDOWS}
{$IFDEF DARWIN}
sType := 'macOS DYLIB';
{$ENDIF DARWIN}
Result := True;
end;
end.
exports
//say_Hello;{$IFDEF DARWIN} name '_say_Hello'; {$ENDIF DARWIN}
say_Hello;
initialization
ShowMessage('[DYLIB] initialization');
finalization
ShowMessage('[DYLIB] finalization');
end.
The Test App:unit uDYLIBTestAPP;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
Forms,
Controls,
Graphics,
Dialogs,
Buttons,
StdCtrls;
type
{ TfDylibTestApp }
TfDylibTestApp = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Memo1: TMemo;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
private
public
end;
const
// Windows DLL Names
{$IFDEF MSWINDOWS}
TestDLL = 'pdylibtest.dll';
{$ENDIF MSWINDOWS}
// macOS DYLIB Names
{$IFDEF DARWIN}
TestDLL = 'pdylibtest';
{$ENDIF DARWIN}
{$IFDEF MSWINDOWS}
function say_Hello(Hello: string): boolean; stdcall; external TestDLL Delayed;
{$ENDIF MSWINDOWS}
{$IFDEF DARWIN}
function say_Hello(Hello: string): boolean; cdecl; external TestDLL;
{$ENDIF DARWIN}
function localFunction(localIn: string; out localOut: string): boolean;
var
fDylibTestApp: TfDylibTestApp;
implementation
function localFunction(localIn: string; out localOut: string): boolean;
begin
LocalOut := 'This was passed to the function: ' + LocalIn;
Result := True;
end;
{$R *.lfm}
{ TfDylibTestApp }
procedure TfDylibTestApp.BitBtn3Click(Sender: TObject);
begin
// Quit the test application
close;
end;
procedure TfDylibTestApp.BitBtn2Click(Sender: TObject);
var
sOut: string;
begin
// This is a local function
ShowMessage('Local Function Call');
if localFunction('Local in', sOut) then
showmessage('Local Function: TRUE (' + sOut + ')')
else
showmessage('Local Function: FALSE');
end;
procedure TfDylibTestApp.BitBtn1Click(Sender: TObject);
var
b:boolean;
sType: string;
sDLLString: string;
begin
b := False;
// Call the DLL Function
{$IFDEF MSWINDOWS}
sType := 'Windows DLL';
sDLLString := 'The string passed to the Windows DLL';
b := say_Hello(sDLLString);
{$ENDIF MSWINDOWS}
{$IFDEF DARWIN}
sType := 'macOS DYLIB';
sDLLString := 'The string passed to the macOS DYLIB';
b := say_Hello(sDLLString);
{$ENDIF DARWIN}
if b then
showmessage('Returned From: ' + sType + ': TRUE')
else
showmessage('Returned From: ' + sType + ': FALSE');
end;
end.