Recent

Author Topic: How to compile the minrtl304 example for 64bit windows ?  (Read 1778 times)

440bx

  • Hero Member
  • *****
  • Posts: 952
How to compile the minrtl304 example for 64bit windows ?
« on: November 06, 2018, 12:49:02 am »
Hello,

I'm trying to compile (and run) the test program found in "minrtl304.zip" of the following thread
https://forum.lazarus.freepascal.org/index.php/topic,41722.msg290584.html#msg290584

I've left everything exactly the way it was, with two exceptions.  I changed the command found in a.bat as shown below:

Code: [Select]
Original command line (found in a.bat)

fpc.exe -va -Xs -XX -Os1 .\test.pas

changed to compile for 64bit to

fpc.exe -va -Xs -XX -Os1 -TWin64 -Px86_64 .\test.pas

The other "change" is that I copied ppcrossx64.exe into the directory where test.pas is (thereby matching the 32bit setup/configuration.)

When compiling for 32bit, everything works great.  When compiling for 64bit, I get the following:

Code: [Select]
lots and lots of information above...

[0.266] Reading object system.o
[0.269] Number of unresolved externals in objects 3
[0.270] Number of unresolved externals after static libraries 3
[0.271] Number of unresolved externals after defining symbols provided by link script 3
[0.274] Number of unresolved externals after defining COMMON symbols 3

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

[0.276] test.pas(3,1) Error: Entrypoint _mainCRTStartup not defined
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[0.277] Number of unresolved externals after DLL imports 0
[0.278] test.pas(3,1) Fatal: There were 1 errors compiling module, stopping
[0.280] Fatal: Compilation aborted
Error: Z:\Training\freepascal - minrtl304\minrtl304\ppcrossx64.exe returned an error exitcode

When compiling for 32bit, the compiler (and linker) seems to find _mainCRTStartup just fine.

When compiling for 64bit, the compiler/linker complains about not finding _mainCRTStartup even though it is defined in sysinitpas.pas.

My question is: what do I have to do to make the linker find _mainCRTStartup so, the linker and I can both be happy ;-)

Thank you for your help.






using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: How to compile the minrtl304 example for 64bit windows ?
« Reply #1 on: November 06, 2018, 08:45:41 pm »
Warning: I don't use 64bit.

When compiling for 64bit, the compiler/linker complains about not finding _mainCRTStartup even though it is defined in sysinitpas.pas.
Regarding sysinitpas, let me quote the compiler source code (for Windows):
Code: Pascal  [Select]
  1. //compiler\systems\t_win.pas
  2.   Procedure GlobalInitSysInitUnitName(Linker : TLinker);
  3. ...
  4.       if cs_profile in current_settings.moduleswitches then
  5.         linker.sysinitunit:='sysinitgprof'
  6.       else if linkcygwin or (Linker.SharedLibFiles.Find('cygwin')<>nil) or (Linker.StaticLibFiles.Find('cygwin')<>nil) then
  7.         linker.sysinitunit:='sysinitcyg'
  8.       else
  9.         linker.sysinitunit:='sysinitpas';
  10.     end;

As you can see, the name of the unit that contains _mainCRTStartup (or its equivalent) is not necessarily sysinitpas.

I guess you can find the name of the unit if you check the produced compiler script (adding -s, I believe). Probably the last unit in the INPUT section. If my guess is right, then giving sysinitpas the expected name should solve finding _mainCRTStartup issue.

440bx

  • Hero Member
  • *****
  • Posts: 952
Re: How to compile the minrtl304 example for 64bit windows ?
« Reply #2 on: November 06, 2018, 10:15:33 pm »
I guess you can find the name of the unit if you check the produced compiler script (adding -s, I believe). Probably the last unit in the INPUT section. If my guess is right, then giving sysinitpas the expected name should solve finding _mainCRTStartup issue.
Engkin, thank you!  :)... that looks like enough information for me to make it work.  I appreciate it.

using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.