Recent

Author Topic: fpc 3.2.2 - main procedure can not find _mainCRTStartup Symbol  (Read 384 times)

paule32

  • Sr. Member
  • ****
  • Posts: 280
fpc 3.2.2 - main procedure can not find _mainCRTStartup Symbol
« on: October 28, 2024, 09:11:00 pm »
Hello,
I would use macro conditions, but I fail.
Below, the code that I use of custom system.pas:

Code: Pascal  [Select][+][-]
  1. {$ifdef winexe}procedure main; stdcall; [public, alias: '_mainCRTStartup'   ];{$endif}
  2. {$ifdef windll}procedure main; stdcall; [public, alias: '_DLLMainCRTStartup'];{$endif}
  3. begin
  4.     PascalMain;
  5. end;

with this command line options (in a console batch file):

Code: Bash  [Select][+][-]
  1. set prjdir=D:\a\TinyRTL\TinyRTL\src
  2. set fpc=ppcrossx64.exe
  3. set fpcsrc=^
  4.     -Fi%prjdir%\sources\fpc-sys ^
  5.     -Fi%prjdir%\sources\fpc-win ^
  6.     -Fi%prjdir%\sources\fpc-rtl ^
  7.     -Fi%prjdir%\sources\fpc-gnu ^
  8.     -Fi%prjdir%\sources\fpc-qt  ^
  9.     ^
  10.     -Fu%prjdir%\sources\fpc-sys ^
  11.     -Fu%prjdir%\sources\fpc-win ^
  12.     -Fu%prjdir%\sources\fpc-rtl ^
  13.     -Fu%prjdir%\sources\fpc-gnu ^
  14.     -Fu%prjdir%\sources\fpc-qt
  15.  
  16. set fpcEXEx64=^
  17.     -n -Mdelphi -Twin64 -dwindows -dwin64 -O3 -Os -Anasmwin64 -a ^
  18.     -dNoRTTI -Xs -g
  19.    
  20. set fpcDLLx64=^
  21.     -fPIC -CD -WD -Xm -Xc -Xg
  22.  
  23. set fpcexe=%fpc% %fpcsrc% %fpcEXEx64%
  24. set fpcdll=%fpc% %fpcsrc% %fpcEXEx64% %fpcDLLx64%
  25.  
  26. %fpcdll% -dwindll testdll.pas -otest1.dll
  27. %fpcexe% -dwinexe test1.pas   -otest1.exe

The error that pop out is:
test1.pas(33,36) Error: Entrypoint _mainCRTStartup not defined

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: fpc 3.2.2 - main procedure can not find _mainCRTStartup Symbol
« Reply #1 on: October 28, 2024, 09:47:39 pm »
Seems the maincrtstartup is in sysinit. Seems you have cut down the RTL a bit too much.

paule32

  • Sr. Member
  • ****
  • Posts: 280
Re: fpc 3.2.2 - main procedure can not find _mainCRTStartup Symbol
« Reply #2 on: October 28, 2024, 10:27:20 pm »
functions in system.pas:

Code: Pascal  [Select][+][-]
  1. procedure fpc_libinitializeunits; [public, alias:'FPC_LIBINITIALIZEUNITS']; compilerproc;
  2. begin
  3.     MessageBoxA(0,PChar('in lib init'),Pchar('oooooo'), 0);
  4. end;
  5.  
  6. procedure exe_main; stdcall; public name '_mainCRTStartup';
  7. begin
  8.     MessageBoxA(0,Pchar('in EXE file'),Pchar('info'),0);
  9.     PascalMain;
  10. end;
  11. procedure dll_main; stdcall; public name '_DLLMainCRTStartup';
  12. begin
  13.     MessageBoxA(0,Pchar('in DLL file'),Pchar('info'),0);
  14.     PascalMain;
  15. end;

whats happend there:

Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. library testdll;
  3.  
  4. procedure test1dll; stdcall;
  5. begin
  6.     MessageBoxA(0,PChar('lulu'),PChar('info'),0);
  7. end;
  8.  
  9. exports
  10.     test1dll;
  11.  
  12. begin
  13.     MessageBoxA(0,Pchar('ooooooo'),PChar('info'),0);
  14.     ExitProcess(0);
  15. end.
  16.  

I can compile the DLL and the EXE, but when I start the EXE, it crashes.
So, the question is: how to create DLL files with FPC 3.2.2 ?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: fpc 3.2.2 - main procedure can not find _mainCRTStartup Symbol
« Reply #3 on: October 28, 2024, 10:38:02 pm »
I don't know. There are simply too many factors to be able to give an answer to these kind of questions . 3rd party Assembling, linking (3rd party?), cut down RTL.

The only solution if you go this way is find your own answers based on inspecting the assembler output (and/or objdumping/disassembling intermediate files).

 

TinyPortal © 2005-2018