Recent

Author Topic: First steps in Cross Compilinig Win64 to Maciintosh  (Read 5910 times)

AL

  • Sr. Member
  • ****
  • Posts: 261
First steps in Cross Compilinig Win64 to Maciintosh
« on: December 16, 2019, 05:14:49 am »
I have an application that works fine in Win 64 and Win 32.  I was able to cross compile that.
That was an easy one.
I would like to try to port it to the MacIntosh world.
My main problem is that I do not know much about Macs.

I have read all wikis and other instructions I cold find but it is still not clear to me.
I kow I wil have to instal a virtual machine to test and debug the program but that is the last item on my list for now.
As a first step I am trying to have the program compile without error.

My questions (for now):
1- Do I need to set the target to Darwin or MacOS
2- What do I select for CPU ?  I know that Apple is trying to go 64 bits only, but for compatibility with older machines is it better to stay 32 bits?
3- What CPU family do I select for 32 bits and 64 bits?
4- I think Cocoa should be the widget set is that correct?    I see some suggestions about QT5
    Which is better / more standard?
5- Do I need to install additionnal components?

I can use all the help I can get
Thank you for educating me!
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

guest64953

  • Guest
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #1 on: December 16, 2019, 05:38:13 am »
I have an application that works fine in Win 64 and Win 32.  I was able to cross compile that.
That was an easy one.
I would like to try to port it to the MacIntosh world.
My main problem is that I do not know much about Macs.

I have read all wikis and other instructions I cold find but it is still not clear to me.
I kow I wil have to instal a virtual machine to test and debug the program but that is the last item on my list for now.
As a first step I am trying to have the program compile without error.

My questions (for now):
1- Do I need to set the target to Darwin or MacOS
2- What do I select for CPU ?  I know that Apple is trying to go 64 bits only, but for compatibility with older machines is it better to stay 32 bits?
3- What CPU family do I select for 32 bits and 64 bits?
4- I think Cocoa should be the widget set is that correct?    I see some suggestions about QT5
    Which is better / more standard?
5- Do I need to install additionnal components?

I can use all the help I can get
Thank you for educating me!

Fpcupdeluxe, man. Remember to have Clang installed on your system first  :)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #2 on: December 16, 2019, 06:20:07 am »
My questions (for now):
1- Do I need to set the target to Darwin or MacOS

Darwin (MacOS is for OS9 I believe )

Quote
2- What do I select for CPU ?  I know that Apple is trying to go 64 bits only, but for compatibility with older machines is it better to stay 32 bits?

Default.

Quote
3- What CPU family do I select for 32 bits and 64 bits?

X86_64 (with the Cocoa widget set) is the only way anyone with the current operating system (Catalina macoS 10.15) will be able to run your app. All 32 bit support has been dropped. My first (Intel Core 2 Duo) Mac mini in 2007 was already 64 bit capable.

Quote
4- I think Cocoa should be the widget set is that correct?    I see some suggestions about QT5.  Which is better / more standard?
5- Do I need to install additional components?

Cocoa! The Cocoa framework comes pre-installed as part of the operating system. With Qt you'll need to install the Qt framework in addition to your app to get your app to run.

Check out the wiki: https://wiki.lazarus.freepascal.org/Portal:Mac

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #3 on: December 16, 2019, 02:15:08 pm »
Thank you, trev this is clear!
I had not found this Wiki yet.  I have a few days more reading :)

hunghung I tried fpcupdeluxe last week, but I have to say I did not understood what it was doing.
Does it install a new copy of Lazarus for each platform we are targetting?  I would rather keep only one installation if possible.  I am not aware of clang, what is that?

Thanks All.
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #4 on: December 16, 2019, 05:09:37 pm »
Does it install a new copy of Lazarus for each platform we are targetting?  I would rather keep only one installation if possible.


It installs a single instance of Lazarus, with cross-compilers for the intended targets.
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #5 on: December 17, 2019, 12:06:26 am »
I made good progress today, thanks to All.
I gave a second try at fpcUpDeluxe and after 2 attemps I could get lazarus, fpc 3.2 and 2 cross compilers installed (Win32 and Darwin).
Both cross-compilers are functionnals.
That is a good start.

Now comes the hard task: eliminate the compiler errors due to platform specific commands.
Is there a reference that would show what units to use instead of the regular windows units for lazarus.

Like instead of

uses  Windows ;

there maybe a uses Darwin?

Like now the compiler does not find HiWord() function.  There is surely an equivalent in some darwin units to be used.
I am also using WaveIN form the MMSystem unit.  This will be the toughest to replace.  Any hints would be welcome.

Again thank you for the help! it is much appreciated.


Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #6 on: December 17, 2019, 12:30:24 am »
Like instead of

uses  Windows ;

there maybe a uses Darwin?

Check the Wiki code examples :)  Hint: there's CocoaAll, MacOSAll to name a few of the macOS specific includes.


dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #7 on: December 17, 2019, 01:47:16 am »
Al, the best way, IMHO, is to set up, in Lazarus, multiple modes.  Then you have a mode for windows and it automatically uses the Windows widget set, similarly for Mac, it uses Cocoa.  That mode data is stored in the lpi file and you can, if you like, use it to build from Lazarus or the command line driven Lazbuild, later being easier for automated build systems.

You can have modes for every target, with and without debugging for example. Makes life a lot easier once setup.

In your code you will have some eg

Code: Pascal  [Select][+][-]
  1. {$ifdef UNIX}A := blah{$endif}
  2. {$ifdef WINDOWS}A := blar{$endif}
  3. StartServer({$ifdef WINDOWS}False{$else}True{$endif});

'UNIX' is perhaps better than using DARWIN, it will cover many of the tests you want to use, and will let you build a Linux version as well. But you will certainly need a few more explicit ones, {$IFDEF DARWIN}.

There are a range of those directives, {$else ...} etc.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #8 on: December 17, 2019, 02:14:48 am »
@ dbannon:  Yes I am using that. Icreated a build mode with Darwin and Cocoa LCL.
                    but I get Identifier not found ; Hiword which I do not get in Windows mode.
                    In windows mode Hiword is in Base.inc which this file:

" This file is part of the Free Pascal run time library.
    This unit contains base definition for the Win32 API
    Copyright (c) 1999-2000 by Florian Klaempfl,
    member of the Free Pascal development team.         "

This is may be why Darwin does not find it as it is a windows inc file.  But there must be an equivalent Darwin/cocoa unit that defines that.
How can I access a list of the available units
Do I need to recompile the IDE with Cocoa?



@terv:  Can you be a bit more specific as to which Wiki.  I can't find any reference to CocoaAll
            Thank you.
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #9 on: December 17, 2019, 02:39:04 am »
@trev:  Can you be a bit more specific as to which Wiki.  I can't find any reference to CocoaAll

The one true Wiki of course! See, for example, https://wiki.freepascal.org/Cocoa_Internals#Units

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #10 on: December 17, 2019, 06:52:14 am »
@ dbannon:  Yes I am using that. Icreated a build mode with Darwin and Cocoa LCL.
                    but I get Identifier not found ; Hiword which I do not get in Windows mode.
                    In windows mode Hiword is in Base.inc which this file:
Hmm, just what is a Hiword ?
Only mention I can find is this - https://wiki.freepascal.org/Mode_MacPas - which says its not available on Mac Mode (no, I don't think you are, or should be, using Mac Mode by the way).

I suggest you find out why your windows code uses HiWord and replace it with a more widespread type if possible. Lets hear from someone more knowledgeable ...

Quote
Do I need to recompile the IDE with Cocoa?
Probably not. If you have a working IDE right now it will produce carbon or cocoa.  But especially with Cocoa, newer is better ! And not for the IDE itself but for the improvements to LCL.  If you using an older version of Lazarus, consider https://wiki.freepascal.org/Installing_Lazarus_on_MacOS_X#Install_Lazarus

As Trev said, its all there in the wiki, its just a bit hard to find !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #11 on: December 17, 2019, 08:05:36 am »
Hmm, just what is a Hiword ?

I think it's something like this:

Code: Pascal  [Select][+][-]
  1. function HiWord(x:longword):word;
  2. begin
  3.     HiWord := (x and $FFFF0000) shr 16;
  4. end;
  5.  

Quote
As Trev said, its all there in the wiki, its just a bit hard to find !

I've been trying to make it easier by consolidating all the macOS-related material in the macOS Portal. The various Portals should be listed on the wiki main page to make life easier for users... but that's for another thread.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #12 on: December 17, 2019, 09:26:17 am »
Hmm, just what is a Hiword ?

I think it's something like this:

Code: Pascal  [Select][+][-]
  1. function HiWord(x:longword):word;
  2. begin
  3.     HiWord := (x and $FFFF0000) shr 16;
  4. end;
  5.  
One can just as well use the Hi and Lo functions. They'll work on all platforms. ;)

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #13 on: December 17, 2019, 03:46:30 pm »
I solve the Hiword by making a local procedure in my unit.
The next one is TimeGetTime!

timeGetTime function

« The timeGetTime function retrieves the system time, in milliseconds. The system time is the time elapsed since Windows was started.
Syntax
C++

DWORD timeGetTime();

Parameters

This function has no parameters.
Return value

Returns the system time, in milliseconds.
Remarks

The only difference between this function and the timeGetSystemTime function is that timeGetSystemTime uses the MMTIME structure to return the system time.

Note that the value returned by the timeGetTime function is a DWORD value. »

There is surely an equivalent in MacOS  just need to find it|

 
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: First steps in Cross Compilinig Win64 to Maciintosh
« Reply #14 on: December 17, 2019, 11:25:43 pm »
There's a discussion of a cross-platform TimeGetTime at https://forum.lazarus.freepascal.org/index.php/topic,41430.0.html

It's macOS btw (previously marketed as Mac OS X and OS X). Mac OS (aka Mac OS Classic) was the pre-Intel variant last released in 2001.

 

TinyPortal © 2005-2018