Recent

Author Topic: is this an issue? export stdcall function in dynamic library on MAC OS  (Read 1469 times)

cai

  • New Member
  • *
  • Posts: 18
create a library project A

there is a function like this:

function func(): Integer;stdcall;
begin
  Result := 0;
end;

exports
  func;

-------------------------------
create an application B

use code like:
var
  func: function (): Integer;stdcall;
begin
  func = GetProcAddress(LoadLirary ('/libA.dylib'), 'func');
  if Assigned(func ) then
    ShowMessage('func  Assigned')
  else
    ShowMessage('func  not Assigned')
end;

run & show "func  not Assigned".
-------------------------------------------
if use cdcel instead of stdcall, will show "func  Assigned"
-------------------------------------------
or, if change exports code like this:
exports
  func name '_func';

also work!

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1492
  • Former Delphi 1-7, 10.2 user
If you use "cdecl", FPC ensures that your function completely adheres to all ABI requirements (naming, parameter passing, etc). If you don't, then you are on your own.
Lazarus 2.1 r65061 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.3 r65500 FPC 3.3.1 r49634 macOS 11.5 aarch64 Xcode 12.5.1
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

 

TinyPortal © 2005-2018