Recent

Author Topic: [SOLVED] Cross-compile windows exe from linux64 machine  (Read 10853 times)

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
[SOLVED] Cross-compile windows exe from linux64 machine
« on: May 14, 2017, 06:07:44 pm »
Hi, I am trying to compile the win32 and win64 executables from a linux64 machine. The wiki says that all you need is to:

1) configure fpc.cfg and get the corresponding cross compiler (I am guessing, ppcross386 and ppcx64, is it right?)
2) configure unit output directory and executable filename using macros in "Project->Project Options->Paths"
3) configure lazarus builds accordingly (Setting Target OS and Target CPU in "Project->Project Options->Config and Target".

As you might guess, I am stuck in step 1.
« Last Edit: May 14, 2017, 08:58:33 pm by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: Cross-compile windows exe from linux64 machine
« Reply #1 on: May 14, 2017, 06:13:56 pm »
Cross-compiling is not easy. After many attempts, I managed to do it so I wrote it down immediately. And this is my recipe to cross-compile Linux64 to Win32:

Quote
01. cd /usr/share/fpcsrc/3.0.2
02. sudo make clean all OS_TARGET=win32 CPU_TARGET=i386
03. sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr
04. sudo ln -sf /usr/lib/fpc/3.0.2/ppcross386 /usr/bin/ppcross386

Note:
You may need to change the path.
I'm using Ubuntu Mate 64-bit.
« Last Edit: May 14, 2017, 06:15:48 pm by Handoko »

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #2 on: May 14, 2017, 07:36:24 pm »
Many thanks for your recipe Handoko! Have anyone managed to do it using the Lazarus IDE?
Be mindful and excellent with each other.
https://github.com/cpicanco/

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #3 on: May 14, 2017, 07:37:42 pm »
Is ppcross386 distributed with FPC 3.0.2 only? Where can I find cross compilers for win32 and win64?
« Last Edit: May 14, 2017, 07:40:22 pm by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: Cross-compile windows exe from linux64 machine
« Reply #4 on: May 14, 2017, 07:49:02 pm »
Is ppcross386 distributed with FPC 3.0.2 only?

Why did you think so?

If I'm not wrong, that ppcross386 is generated because you run the crossinstall command.

If you succeed what I recommend, now you should be able to create windows exe file. But you need to configure your project option like this below:

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #5 on: May 14, 2017, 07:55:48 pm »
Hi Handoko, first of all thank you for your support. It was not clear for me that your recipe was for compiling the cross compiler. May I ask where should I navigate to execute the recipe? Or just opening the terminal anywhere would be enough? 

___

"cd /usr/share/fpcsrc/"

Ok, ok. I was deluded by the fpc3.0.2. Will try with fpc3.0.0, paths may change. Sorry about that.
« Last Edit: May 14, 2017, 07:59:16 pm by cpicanco »
Be mindful and excellent with each other.
https://github.com/cpicanco/

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #6 on: May 14, 2017, 07:57:19 pm »
I will try to update the wiki with a step-by-step if I figure out how to do it.
Be mindful and excellent with each other.
https://github.com/cpicanco/

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #7 on: May 14, 2017, 08:02:02 pm »
something like:

// navigate to your fpc folder, NOTE: paths may change from OS to OS.
01. cd /usr/share/fpcsrc/3.0.2

// compile and intall the crosscompile
02. sudo make clean all OS_TARGET=win32 CPU_TARGET=i386
03. sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr

// link the compiler so that lazarus can see it NOTE: paths may change from OS to OS.
04. sudo ln -sf /usr/lib/fpc/3.0.2/ppcross386 /usr/bin/ppcross386
Be mindful and excellent with each other.
https://github.com/cpicanco/

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: Cross-compile windows exe from linux64 machine
« Reply #8 on: May 14, 2017, 08:07:17 pm »
Oh sorry, I guess you're familiar with Linux Terminal.

Quote
01. cd /usr/share/fpcsrc/3.0.2
02. sudo make clean all OS_TARGET=win32 CPU_TARGET=i386
03. sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr
04. sudo ln -sf /usr/lib/fpc/3.0.2/ppcross386 /usr/bin/ppcross386

You should run the steps above using Terminal. You may need to change the path, for example if you're using FPC 2.64 then it should be ..../fpcsrc/2.6.4 and ..../fpc/2.6.4

After you finished the steps above your Lazarus/FPC should be able to generate windows binaries.

But (if you're using Lazarus), you should change your project options. To do it:
Lazarus main menu > Project > Project > Options > Config and Target > Target OS = win32 and Target CPU family = i386

Note:
- You should remove the steps' number: "01.", "02.", "03.", "04."
- I don't familiar with Debian, I use Ubuntu (Debian fork) so I think the path should be same between those OS
- But the path should change if you're using FPC other than version 3.0.2

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #9 on: May 14, 2017, 08:13:42 pm »
Hi, I successifully compiled the crosscompiler but when closing the Lazarus Project window I am receiving an error saying that:

Compiler "/usr/bin/fpc" does not support target i386-win32

Should I change the lazarus compiler path? Or is there a better option?
Be mindful and excellent with each other.
https://github.com/cpicanco/

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: Cross-compile windows exe from linux64 machine
« Reply #10 on: May 14, 2017, 08:16:52 pm »
Try to rebuild your Lazarus:
Lazarus main menu > Tools > Build Lazarus with Profile: Normal IDE > wait several minutes and restart Lazarus

You now should able to generate Windows binaries but you can't run it nor debug it using Lazarus IDE.

You may install WINE and run the .exe binaries or you can use VirtualBox or anything similar.

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #11 on: May 14, 2017, 08:25:20 pm »
Rebuild Lazarus and the error persists. I will investigate this further. Thank you for you attention Handoko. If anyone have a guess about what is the next step, I would really appreciate your comments!
Be mindful and excellent with each other.
https://github.com/cpicanco/

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: Cross-compile windows exe from linux64 machine
« Reply #12 on: May 14, 2017, 08:32:45 pm »
Have you make sure the 4 steps I gave you run successfully without error?

cpicanco

  • Hero Member
  • *****
  • Posts: 674
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Cross-compile windows exe from linux64 machine
« Reply #13 on: May 14, 2017, 08:34:30 pm »
Yes, step 4 failed. Fixed it and now the IDE is building win32 binaries!!!! :D
Be mindful and excellent with each other.
https://github.com/cpicanco/

Handoko

  • Hero Member
  • *****
  • Posts: 5545
  • My goal: build my own game engine using Lazarus
Re: Cross-compile windows exe from linux64 machine
« Reply #14 on: May 14, 2017, 08:37:32 pm »
That's great.

 

TinyPortal © 2005-2018