Recent

Author Topic: Cross compiling from linux64 to win64  (Read 1661 times)

process_1

  • Guest
Cross compiling from linux64 to win64
« on: July 17, 2020, 08:10:36 pm »
https://wiki.freepascal.org/Cross_compiling

Here is available all variations except cross compiling from linux64 to win64.

Perhaps I'm missing that guide?

lucamar

  • Hero Member
  • *****
  • Posts: 3020
Re: Cross compiling from linux64 to win64
« Reply #1 on: July 17, 2020, 09:59:19 pm »
It should be basically the same as Cross compiling for Win32 under Linux, only changing "win32" for "win64", "i386" by "x86_64", and so on.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

process_1

  • Guest
Re: Cross compiling from linux64 to win64
« Reply #2 on: July 18, 2020, 02:31:48 am »
Installed:
Code: [Select]
sudo apt install mingw-w64 mingw-w64-tools
sudo ln -s /usr/bin/x86_64-w64-mingw32-windres /usr/bin/windres

sudo dpkg -i fpc-src_3.2.0-1_amd64.deb
sudo dpkg -i fpc-laz_3.2.0-1_amd64.deb
sudo dpkg -i lazarus-project_2.0.10-0_amd64.deb

Win32:

Code: [Select]
cd /usr/share/fpcsrc/3.2.0
sudo make clean all OS_TARGET=win32 CPU_TARGET=i386
sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr
sudo ln -sf /usr/lib/fpc/3.2.0/ppcross386 /usr/bin/ppcross386

Win64:
Code: [Select]
cd /usr/share/fpcsrc/3.2.0
sudo make clean all OS_TARGET=win64 CPU_TARGET=x86_64
sudo make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=/usr
sudo ln -sf /usr/lib/fpc/3.2.0/ppcrossx64 /usr/bin/ppcrossx64

Accordingly, ppccross* are sym linked correctly and can be executed from any active directory :

Code: [Select]
file:///usr/bin/ppcrossx64
file:///usr/bin/ppcross386

Cross compiling with Win32 settings works fine, however not with Win64. When switch to Win64 settings, error window with following content is shown:

"
The project uses target OS=win64 and CPU=x86_64.
The system.ppu for this target was not found in the FPC binary directories.
Make sure fpc is installed correctly for this target and the fpc.cfg contains the right directories.
"

Obviously, something is missing here, however I'm not certain what.
« Last Edit: July 18, 2020, 02:43:31 am by process_1 »

dbannon

  • Hero Member
  • *****
  • Posts: 1148
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Cross compiling from linux64 to win64
« Reply #3 on: July 18, 2020, 02:53:59 am »
These are my notes relating to windows  from when I setup my Linux64 to L32, W32, W64 cross compiler, they assume you are using a package installed compiler (ie probably 3.0.4) installed in root space (so must be done as root).  Last time I did it it was with a tarball compiler in user space. I used these notes but unfortunatly I did not update them.

(I should probably do it again and update my notes AND the wiki page)

Code: Pascal  [Select][+][-]
  1. # Setup 32bit and 64 bit Windows
  2. cd /usr/share/fpcsrc/$FPCVER
  3. make clean all OS_TARGET=win32 CPU_TARGET=i386
  4. make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr
  5. ln -sf /usr/lib/fpc/$FPCVER/ppcross386 /usr/bin/ppcross386
  6.  
  7. make clean all OS_TARGET=win64 CPU_TARGET=x86_64
  8. make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=/usr
  9. ln -sf /usr/lib/fpc/$FPCVER/ppcrossx64 /usr/bin/ppcrossx64
  10.  
  11. # Make sure its all there (we should see ppcross386, ppcrossx64)
  12. echo "watch for ppcross386, ppcrossx64"
  13. ls -la /usr/lib/fpc/$FPCVER/ppcross*
  14. ls -la /usr/bin/ppcross*


Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Fred vS

  • Hero Member
  • *****
  • Posts: 1838
    • StrumPract is the musicians best friend
Re: Cross compiling from linux64 to win64
« Reply #4 on: July 18, 2020, 03:05:08 am »
For cross-compiling from Linux to Windows, you may also use fpc.exe (32 and 64 bit) via wine (Windows emulator).
You may even use the fpc Windows installer via wine.

It works perfectly and your code is compiled by a native Windows compiler.
« Last Edit: July 18, 2020, 03:06:57 am by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

dbannon

  • Hero Member
  • *****
  • Posts: 1148
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Cross compiling from linux64 to win64
« Reply #5 on: July 18, 2020, 03:29:06 am »
For cross-compiling from Linux to Windows, you may also use fpc.exe (32 and 64 bit) via wine (Windows emulator).
You may even use the fpc Windows installer via wine.

Always good to have an alterative approach. But would seem a lot of install if you are not otherwise a Wine user ?  And having a "native" cross compiler lets you, for example, run a script that builds all your targets (and, in the case of https://github.com/tomboy-notes/tomboy-ng/blob/master/package/package.bash do some packaging). FPC is so good at cross compiling, surprises me that people have trouble.

But I would like to add Mac Cocoa and Raspberry Pi to my script mentioned above. At present, I build them separately.

Davo

Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Fred vS

  • Hero Member
  • *****
  • Posts: 1838
    • StrumPract is the musicians best friend
Re: Cross compiling from linux64 to win64
« Reply #6 on: July 18, 2020, 03:50:50 am »
Quote
But would seem a lot of install if you are not otherwise a Wine user ?

Yes of course wine must be installed.

After this, I just do:

Code: Pascal  [Select][+][-]
  1. wine /directory/of/fpc.exe myprogram.pas

And no need to install anything else.

The advantage to use wine is that after compilation you may run and test your Windows executable with wine.
« Last Edit: July 18, 2020, 03:54:57 am by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

process_1

  • Guest
Re: Cross compiling from linux64 to win64
« Reply #7 on: July 18, 2020, 04:12:08 am »
Wine is quite a ballast. Anyway, I have it installed on dev machine. What was the problem in the past is that Lazarus through wine didn't worked fine, some other executables as well etc. Thus where main difference and the reason to test executable on native OS...

I would also like to have cross-compiling  for Mac (OS X) on Linux, however, as far I have understood (I'm not a lawyer), that is forbidden by Apple license...

Anyway, my original issue with cross-compiling  on Linux64 to Win64 persists and I'm not certain what causing it, as error message is quite confusing, probably not point to the right cause as compiling and installing cross-platform fpc went without an issue.
« Last Edit: July 18, 2020, 04:19:21 am by process_1 »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 935
  • Former Delphi 1-7, 10.2 User
Re: Cross compiling from linux64 to win64
« Reply #8 on: July 18, 2020, 05:13:52 am »
What do you have listed as the compiler in Tools > Options > Compiler executable ? This has caught me out in the past.
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

dbannon

  • Hero Member
  • *****
  • Posts: 1148
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Cross compiling from linux64 to win64
« Reply #9 on: July 18, 2020, 05:32:26 am »

Anyway, my original issue with cross-compiling  on Linux64 to Win64 persists and I'm not certain what causing it, as error message is quite confusing, probably not point to the right cause as compiling and installing cross-platform fpc went without an issue.

OK, I should have read your message more carefully, its a lazarus setup issue rather than compiler by the sound of it.

OK, lets check how Lazarus is setup then ?

Tools->Options->Environment
....
Compiler executable (eg fpc)
= /home/dbannon/bin/FPC/fpc-3.2.0/bin/fpc


Project Options

Config and target
     Target OS (-T) = Win64
     Target CPU family (-P) = x86_64

Additions and Overrides
     (its a grid, for this mode, Win64 release I have ticked  -)
     LCLWidgetType := win32
   
Compiler Commands
     Compiler
               Command = ppcrossx64

The path to ppcross64 is indicated by the which command -

dbannon@uMate2004bVB:~$  which ppcrossx64 [enter]
/home/dbannon/bin/FPC/fpc-3.2.0/bin/ppcrossx64


Important that your compiler be set to fpc and that fpc be able o find an appropriate ppcrossx64 in its path.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

process_1

  • Guest
Re: Cross compiling from linux64 to win64
« Reply #10 on: July 18, 2020, 07:26:22 am »
All is set correctly, AFAICS, but still the error is the same.

which ppcrossx64 -> /usr/bin/ppcrossx64

system.ppu is phisically present here:
/usr/share/fpcsrc/3.2.0/rtl/units/x86_64-win64

Because of that, the error have no sense.

It is funny, but where are i386 compiled files (ppu) ? These are not present in /usr/share/fpcsrc/3.2.0/rtl/units/ !

Here are only two directories listed:
x86_64-linux
x86_64-win64

Anyway, cross-compilation for i386 (and native Linux64) works fine from Lazarus, but not for Win64.

BTW, LCLWidgetType = win32 shouldn't have anything related with win64? Anyway, checking it back brings the same error.
« Last Edit: July 18, 2020, 07:43:42 am by process_1 »

dbannon

  • Hero Member
  • *****
  • Posts: 1148
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Cross compiling from linux64 to win64
« Reply #11 on: July 18, 2020, 07:56:10 am »
OK, try -

ppcrossx64 -it [enter]

The list should include Win64.

Yes, you should be using the win32 widgets, thats all there is.

Look in your Lazarus directory, lcl/units/x86_64-win64, you should have a whole lot of *.o files there, I suspect you won't.

If you compiled your own Lazarus, you will know where to find those files, if its a package install, and therefore in root space, its a bit harder. From memory it will be in your home directory, .lazarus and down a few levels because Lazarus makes new files there because it cannot write to to the ones in root space (thats why I always build my own!).

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

process_1

  • Guest
Re: Cross compiling from linux64 to win64
« Reply #12 on: July 18, 2020, 08:22:34 am »
Code: [Select]
$ ppcrossx64
Free Pascal Compiler version 3.2.0 [2020/07/17] for x86_64
Copyright (c) 1993-2020 by Florian Klaempfl and others
/usr/lib/fpc/3.2.0/ppcrossx64 [options] <inputfile> [options]
 Put + after a boolean switch option to enable it, - to disable it.
...

The  /usr/share dir is not under root privileges, nor it is any file here.

BTW, i386 comiled dir is here: ~/.lazarus/lib/LazUtils/lib/i386-win32 . But win64 is in the share dir!

I beleve the mess is made here by mixing directories by compilation process itself, which cannot be my fault as I did all by recommended guide.

When components are added in lazarus, it will recompile istelf, the executable will be placed in ./lazarus, as well as  all compiled system files should be there, not in share dir, except for native platform FPC compiler.

Then, why when compiled cross-compiler for Win64 files are stored in share dir?

That probably makes real mess. Moving all win64 compiled dirs to ./lazarus by side of i386, then all will probably work.

Let see...
« Last Edit: July 18, 2020, 08:29:29 am by process_1 »

process_1

  • Guest
Re: Cross compiling from linux64 to win64
« Reply #13 on: July 18, 2020, 08:36:36 am »
No, that will not be possible as all compilations for Win64 where under individual libs subdir...

It is quite a mess (bad idea, at least) mixing share and ./lazarus directories! I have no idea how to fix that, instead developers itself to look what they did...  
« Last Edit: July 18, 2020, 08:49:16 am by process_1 »

process_1

  • Guest
Re: Cross compiling from linux64 to win64
« Reply #14 on: July 18, 2020, 08:54:44 am »
BTW, object files (*.o files) for Win64 are in share dir (along with ppu).

 

TinyPortal © 2005-2018