Recent

Author Topic: fpc 3.2.2 how to export Functions with same Name and different Arguments ?  (Read 584 times)

paule32

  • Hero Member
  • *****
  • Posts: 645
  • One in all. But, not all in one.
Hello,
how can I "export" these three Functions ?

Code: Pascal  [Select][+][-]
  1. function CharArrToAnsiStr(const A: array of AnsiChar): AnsiString; overload; stdcall; export;
  2. function CharArrToAnsiStr(const A: array of AnsiChar; BufLen: Integer): AnsiString; overload; stdcall; export;
  3. function CharArrToAnsiStr(P: PAnsiChar; BufLen: Integer): AnsiString; overload; stdcall; export;
  4.  
  5. exports
  6.   ...
  7.   ?
  8.   ;
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Fibonacci

  • Hero Member
  • *****
  • Posts: 788
  • Internal Error Hunter
Not possible. Use unique names.

paule32

  • Hero Member
  • *****
  • Posts: 645
  • One in all. But, not all in one.
Hello @fibonacci

nice to see you.
I have add a discussion on our project for details see the new repro
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12706
  • FPC developer.
Linker namespaces usually only support unique symbols. Export the three overload functions "as" three different linker names, then when importing declare them overloaded again.

paule32

  • Hero Member
  • *****
  • Posts: 645
  • One in all. But, not all in one.
for @all others:

I formed a well working export functionallity:

Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. unit SysUtils;
  3.  
  4. interface
  5. uses Windows;
  6.  
  7. {$ifdef DLLEXPORT}
  8. function ChATAStr1(const A: array of AnsiChar): AnsiString;                  overload; stdcall; export;
  9. function ChATAStr2(const A: array of AnsiChar; BufLen: Integer): AnsiString; overload; stdcall; export;
  10. function ChATAStr3(P: PAnsiChar; BufLen: Integer): AnsiString;               overload; stdcall; export;
  11. {$endif DLLEXPORT}
  12.  
  13. {$ifdef DLLIMPORT}
  14. function  CharArrToAnsiStr(const A: array of AnsiChar): AnsiString;                  overload; stdcall; external RTLDLL name 'ChATAStr1';
  15. function  CharArrToAnsiStr(const A: array of AnsiChar; BufLen: Integer): AnsiString; overload; stdcall; external RTLDLL name 'ChATAStr2';
  16. function  CharArrToAnsiStr(P: PAnsiChar; BufLen: Integer): AnsiString;               overload; stdcall; external RTLDLL name 'ChATAStr3';
  17. {$endif DLLIMPORT}
  18.  
  19. implementation
  20.  
  21. {$ifdef DLLEXPORT}
  22. function ChATAStr1(const A: array of AnsiChar): AnsiString; overload; stdcall; export; begin ... end;
  23. function ChATAStr2(const A: array of AnsiChar; BufLen: Integer): AnsiString; overload; stdcall; export; begin ... end;
  24. function ChATAStr3(P: PAnsiChar; BufLen: Integer): AnsiString; overload; stdcall; export; begin ... end;
  25. {$endif DLLEXPORT}
  26.  
  27. {$ifdef DLLEXPORT}
  28. exports
  29.   ChATAStr1 name 'ChATAStr1',
  30.   ChATAStr2 name 'ChATAStr2',
  31.   ChATAStr3 name 'ChATAStr3'
  32.   ;
  33. {$endif DLLEXPORT}
  34.  
  35. end.

Then I built the EXE with a Batch File:

Code: Bash  [Select][+][-]
  1. fpc -dDLLEXPORT -n -B -Os -CD RTLLib.pas
  2. dlltool --input-def rtllib_dll.def --dllname rtllib.dll --output-lib librtllib_dll.a
  3. fpc -dDLLIMPORT -n -B -Os test.pas
  4. strip test.exe
  5. strip rtllib.dll
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

 

TinyPortal © 2005-2018