Recent

Author Topic: How to Lazarus Cross Compile Win32 to Linux ?  (Read 17363 times)

loaded

  • Hero Member
  • *****
  • Posts: 824
How to Lazarus Cross Compile Win32 to Linux ?
« on: May 22, 2017, 09:18:10 am »
Hi All,

The operating system I use is win7 64, lazarus version 1.6.4 win32
I want to cross-compile but I could not solve the problem at hand.

Compile package FCL 1.0.1: Exit code 1, Errors: 1
Fatal: Cannot find system used by fcllaz of package FCL.

Thank you for helping.



Check out  loaded on Strava
https://www.strava.com/athletes/109391137

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #1 on: May 22, 2017, 02:12:04 pm »
Have you tried to download 7z file from the location shown in the 1st screenshot and unpack to your libraries directory?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #2 on: May 22, 2017, 02:57:32 pm »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #3 on: May 23, 2017, 03:09:27 am »
Well, cross compilers in fpcupdeluxe and codetyphon work out of the box if you check their installation.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #4 on: May 24, 2017, 09:35:28 am »
Thank you for the answer avra
I am investigating the subject.
I think it is necessary to work directly on the target platform for a smooth compilation.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1738
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #5 on: May 24, 2017, 09:49:58 am »
Quote
I think it is necessary to work directly on the target platform for a smooth compilation.

The above is not necessary true.
Please try fpcupdeluxe. It should make cross-life easy.
But follow the instructions; add this into your lpr:
{$IFDEF FPC_CROSSCOMPILING}
  {$IFDEF LINUX}
    {$linklib libc_nonshared.a}
  {$ENDIF}
{$ENDIF}

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #6 on: May 25, 2017, 07:25:42 am »
Thank you for the answer DonAlfredo
Code: Pascal  [Select][+][-]
  1. {$IFDEF FPC_CROSSCOMPILING}
  2.   {$IFDEF LINUX}
  3.     {$linklib libc_nonshared.a}
  4.   {$ENDIF}
  5. {$ENDIF}
  6.  
I tried the codes again the same error.
I installed the codetyphon program. He also made the same mistake.
Now I have no choice but to install linux and work directly on the target platform. :(
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1738
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #7 on: May 25, 2017, 07:49:05 am »
Well, you have freedom of choice naturally.

But did you really follow all 4 steps needed to install a cross-compiler.
And did you start Lazarus with the provided link?

tomek1

  • New Member
  • *
  • Posts: 16
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #8 on: November 25, 2017, 04:47:42 pm »
I'm trying to cross compile simple program with fpcupdeluxe.
I've followed 4 steps as shown above, but get compilation error:
Fatal: Can't find unit system used by project1

fpcupdeluxe-i386-win32  v.1.6.0i, Trunk
Windows 10 64bit
cross compiler installed: x86_64 - linux
Code: Pascal  [Select][+][-]
  1. program project1;
  2. {$IFDEF FPC_CROSSCOMPILING}
  3.   {$IFDEF LINUX}
  4.     {$linklib libc_nonshared.a}
  5.   {$ENDIF}
  6. {$ENDIF}
  7. begin
  8.   writeln('simple program');
  9.   readln;
  10. end.
Compiler Options:
Libraries: {InstallDir}\cross\lib\x86_64-linux\
Target: Linux
« Last Edit: November 25, 2017, 04:51:15 pm by tomek1 »

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1738
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #9 on: November 25, 2017, 04:55:11 pm »
You need to define the target (Linux) and CPU (x86_64). You do not need to define the library location.
Better also to give a bit more info about the error. Makes solving easier.

tomek1

  • New Member
  • *
  • Posts: 16
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #10 on: November 25, 2017, 06:05:49 pm »
Target CPU was set to default. setting to x86_64 solves the error :)
thx again.
P.S. what about error, I was getting only 1 line compile error, don't know if there's a way to get more.

guest60499

  • Guest
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #11 on: November 26, 2017, 12:53:02 am »
From memory, the options exist in the IDE regardless of whether or not the required binaries and libraries are there. It seems to me, then, that you may not have installed the proper packages. The error message seems to indicate this. It took me a long time to get everything set up properly, even on Linux.

Now I have no choice but to install linux and work directly on the target platform. :(
This should not be necessary, but I suppose it is worthwhile to point out that the Wiki page on cross compiling indicates that compiling for Linux from Windows is much more difficult. Sadly it does not state why, which is a glaring omission.

If I had to guess, it is because the project was developed primarily on POSIX compliant operating systems and the build tools are hard to run in Window's command prompt or PowerShell. However, Cygwin is POSIX compliant, and you should be able to run all of the build tools within Cygwin. It should add no dependency on Cygwin to the produced Lazarus/FPC or to your program, and will not affect your license.

So, install Cygwin, make sure you have the "build-essentials" packages (make, etc.), and try to build Lazarus/FPC. Or use fpcupdeluxe which I suspect does most of the same thing, e.g. making sure environment variables are set properly. Personally I prefer to avoid fpcupdeluxe, it seems odd.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #12 on: November 26, 2017, 01:26:39 am »
This should not be necessary, but I suppose it is worthwhile to point out that the Wiki page on cross compiling indicates that compiling for Linux from Windows is much more difficult. Sadly it does not state why, which is a glaring omission.

If I had to guess, it is because the project was developed primarily on POSIX compliant operating systems and the build tools are hard to run in Window's command prompt or PowerShell. However, Cygwin is POSIX compliant, and you should be able to run all of the build tools within Cygwin. It should add no dependency on Cygwin to the produced Lazarus/FPC or to your program, and will not affect your license.
Partly the issue. You can use mingw to circumvent the use of Cygwin environment.

However, you 1) need the binutils (in case processor is same this is do-able but can get complicated pretty fast when they differ) and b) fpc is not all you need. You also require the startup files for your platform and which is very platform specific. They either need to be compiled on windows (in case windows is your host) or copy them from existing target. Besides that you require all other libraries that you need to link against when compiling for linux target. That is mandatory.

Since there are different distro's these files to compile against differ, not to mention that a distro can exist for even so many target processors (bitwidth, endianess, other specifics such as hardfloat/softfloat). So none of them are compatible with eachother.

And we did not even start with lazarus there, which has a lot more dependencies.

Putting that all into practice means a lot of work that is very difficult (if not impossible) to automate. Doing the manual labour is too much for most as it requires a fair amount of knowledge/experience. In short: not worth the effort. You are much faster setting up a VM/emulator and run your linux distro there.
« Last Edit: November 26, 2017, 01:37:02 am by molly »

guest60499

  • Guest
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #13 on: November 26, 2017, 02:58:47 am »
Putting that all into practice means a lot of work that is very difficult (if not impossible) to automate. Doing the manual labour is too much for most as it requires a fair amount of knowledge/experience. In short: not worth the effort. You are much faster setting up a VM/emulator and run your linux distro there.
Right, I just found some of this that I had missed. I think that requirement is extremely odd and is what makes the process unworkable. It is more reasonable to insist that a user maintain an installation of a cross compiler, but then it is still difficult to maintain all necessary system libraries. Gentoo's prefix/RAP does what is necessary, but Cygwin support is spotty at best. And it shows the difficulty of the problem - prefix/RAP relies on Portage, a package manager.

I suppose what OP asked is intractable due to the difficulty of cross compiling for Linux from Windows. If very close attention is paid to the libraries used it is likely possible, but the resulting binary is only guaranteed to work on one distribution or with one set of library versions.

Having just tried to compile in Cygwin, it's necessary to add your existing Lazarus's FPC directory to your PATH. Also notable is that it's not expected that one would build FPC 3.0.4 with FPC 3.0.4, so I had to change a variable definition.

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1738
Re: How to Lazarus Cross Compile Win32 to Linux ?
« Reply #14 on: November 26, 2017, 08:35:28 am »
Quote
Personally I prefer to avoid fpcupdeluxe, it seems odd.
I am ok with your opinion, but just out of curiosity: what is odd about it ?

 

TinyPortal © 2005-2018