Recent

Author Topic: Command line compilation to windows 64 bit target  (Read 1463 times)

DenReq

  • New member
  • *
  • Posts: 8
Command line compilation to windows 64 bit target
« on: May 16, 2022, 10:39:21 am »
Hello,

Sorry for the probably basic questions, but I don't understand how to get a 64 bit windows build of an application with the command line compiler version. The installation binaries do seem to indicate that this target is taken into account, but the FPC compiler does not know it.

I have done, with some difficulty, a complete recompilation of the libraries and compiler, but the problem remains the same.

Is it possible to find somewhere a procedure explaining how to activate the compilation for a win64 target? I'm under the impression that everyone uses Lazarus rather than the command line version, do I really need to do the same (which would be a problem in my case)?

Thanks in advance for any help.

EDIT : I've made a bit of progress, so maybe I'll be able to figure it out on my own eventually. :)
« Last Edit: May 16, 2022, 04:59:23 pm by DenReq »

440bx

  • Hero Member
  • *****
  • Posts: 3921
Re: Command line compilation to windows 64 bit target
« Reply #1 on: May 16, 2022, 11:20:32 am »
Is it possible to find somewhere a procedure explaining how to activate the compilation for a win64 target?
did you download/install the cross compiler ppcrossx64.exe ?  that's the version of the compiler that can produce a 64bit executable for Windows.

if you don't have that executable installed then you need to download/install it.

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Command line compilation to windows 64 bit target
« Reply #2 on: May 16, 2022, 11:24:27 am »
If you use the combined FPC 32+64-bit installer, try compiling with

fpc -Px86_64 -Twin64

The -P option selects a different compiler binary (ppcrossx64) and then the 64-bit options are available. The -Twin64 might not be necessary.

DenReq

  • New member
  • *
  • Posts: 8
Re: Command line compilation to windows 64 bit target
« Reply #3 on: May 16, 2022, 12:16:24 pm »
Thanks a lot for your replies, it seems to be better with your indications indeed.

I was able to recompile the RTL and the libraries in 32 bits. If I want to do the same thing in 64 bits, is there a procedure for that too, or do I have to modify the makefile myself?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Command line compilation to windows 64 bit target
« Reply #4 on: May 16, 2022, 12:18:30 pm »

make all CPU_TARGET=x86_64  OS_TARGET=win64   

in the toplevel FPC sources directory.


DenReq

  • New member
  • *
  • Posts: 8
Re: Command line compilation to windows 64 bit target
« Reply #5 on: May 16, 2022, 04:27:50 pm »
Thank you very much again.

Unfortunately the compilation fails in rtl\win64, with this message:

Makefile:216: *** The Makefile doesn't support target i386-win64, please run fpcmake first.  Stop.

It's quite complicated to understand for a novice how to fix this problem... I've tried to do different things by digging in the docs, but without success so far.

Maybe I should give up rebuilding the units? Actually I only need to be able to set a low level callback when an exception is raised, so I can log all exceptions. If this is possible without rebuilding system and sysutils, it would certainly be much easier for me. But I haven't seen how I could do that yet.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11351
  • FPC developer.
Re: Command line compilation to windows 64 bit target
« Reply #6 on: May 16, 2022, 06:21:54 pm »
Thank you very much again.

Unfortunately the compilation fails in rtl\win64, with this message:

Makefile:216: *** The Makefile doesn't support target i386-win64, please run fpcmake first.  Stop.

Somehow the CPU_TARGET bit hasn't been passed. Please post your exact commandline and the info of "make info"

Quote
It's quite complicated to understand for a novice how to fix this problem... I've tried to do different things by digging in the docs, but without success so far.

Most novices use the prebuild versions, specially on Windows. One of the problems with own build on Windows is other copies (in the %path%) of certain core binaries.

Quote
Maybe I should give up rebuilding the units? Actually I only need to be able to set a low level callback when an exception is raised, so I can log all exceptions. If this is possible without rebuilding system and sysutils, it would certainly be much easier for me. But I haven't seen how I could do that yet.

Exceptions are usually not logged on pointer of creation. Doing so might slow down your program, as e.g. EConvertError might be called a lot during running, but is usually locally handled.

Exceptions are usually logged when it bubbles up to the toplevel core loop, and using Application.onexception is fine for e.g. the main thread. Or a simple top level try.. except  frame if you are a console application.


DenReq

  • New member
  • *
  • Posts: 8
Re: Command line compilation to windows 64 bit target
« Reply #7 on: May 17, 2022, 11:56:05 am »
Thank you Marcov.

I've made some progress and can now compile what I need, after understanding better how to use fpcmake.

For the logs, I plan to use a system allowing to manage the recording in an asynchronous way, that I had developed with an old version of FPC (in 2005).

Otherwise I have a problem that looks like a bug. If two divisions by 0 occur consecutively in a thread, only the 1st one generates an exception, the next one returns in the result +Inf. I see this in a test DLL that I compile with FPC, without any particular code. The problem disappears if I comment out the loading of the MXCSR register in SysResetFPU (file x86_64.inc).

Code: Pascal  [Select][+][-]
  1. {$define FPC_SYSTEM_HAS_SYSRESETFPU}
  2. Procedure SysResetFPU;
  3.   var
  4.     { these locals are so we don't have to hack pic code in the assembler }
  5.     localmxcsr: dword;
  6.     localfpucw: word;
  7.   begin
  8.     localfpucw:=Default8087CW;
  9.     localmxcsr:=DefaultMXCSR;
  10.     asm
  11.       fninit
  12.       fwait
  13.       fldcw   localfpucw
  14.       //ldmxcsr localmxcsr
  15.     end;
  16.   end;
  17.  

I'm not sure what to think about this problem, can disabling the reloading of the register cause other problems? I don't plan to use the SSE instructions in my program.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Command line compilation to windows 64 bit target
« Reply #8 on: May 17, 2022, 02:11:23 pm »
Hmm, it seems that for some reason the FPU exception mask is not initialized correctly for a new thread (at least on i386-win32 and x86_64-win64). I'll have to check that.

Using Math.SetExceptionMask you can control per thread whether floating point exceptions are supposed to happen or not (this will then also be used for the next SysResetFPU). Modifying SysResetFPU should not be necessary.

I don't plan to use the SSE instructions in my program.

But you're using floating point types and thus - at least on x86_64-win64 - you're implicitly using SSE.

Edit: SetExceptionMask is not per thread.
« Last Edit: May 17, 2022, 02:37:38 pm by PascalDragon »

DenReq

  • New member
  • *
  • Posts: 8
Re: Command line compilation to windows 64 bit target
« Reply #9 on: May 17, 2022, 02:58:22 pm »
Thank you, I think I understand where the problem can come from.

In my case, the threads are created in the host application (not FPC) and call functions located in a DLL compiled with FPC. So the thread-specific FPU initialization code is not called, so it seems logical.

I'll probably have to take some of the thread initialization code and call it at the beginning of these functions...

DenReq

  • New member
  • *
  • Posts: 8
Re: Command line compilation to windows 64 bit target
« Reply #10 on: May 17, 2022, 03:34:33 pm »
Well, I've tried a lot of things but the only one that seems to work in my situation, at least from an interrupt generation point of view, is to disable MXCSR loading in SysResetFPU...

 

TinyPortal © 2005-2018