Lazarus

Using the Lazarus IDE => General => Topic started by: loaded on May 22, 2017, 09:18:10 am

Title: How to Lazarus Cross Compile Win32 to Linux ?
Post by: loaded 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.



Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: avra 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?
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: loaded on May 22, 2017, 02:57:32 pm
Thanks avra
Yes ;
 https://www.youtube.com/watch?v=qT9fm0lQA7I  (https://www.youtube.com/watch?v=qT9fm0lQA7I) watched the video
Then I downloaded the file  http://www.pilotlogic.com/codetyphon/libraries/i386-linux.7z (http://www.pilotlogic.com/codetyphon/libraries/i386-linux.7z)
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: avra 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.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: loaded 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.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: DonAlfredo 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}
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: loaded 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. :(
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: DonAlfredo 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?
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: tomek1 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
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: DonAlfredo 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.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: tomek1 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.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: guest60499 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 (http://wiki.lazarus.freepascal.org/Cross_compiling#From_Windows_to_Linux) 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.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: molly 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 (http://wiki.lazarus.freepascal.org/Cross_compiling#From_Windows_to_Linux) 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.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: guest60499 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.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: DonAlfredo 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 ?
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: guest60499 on November 27, 2017, 07:48:18 am
I am ok with your opinion, but just out of curiosity: what is odd about it ?
It is a program purpose built to compile FPC, instead of a build configuration for a dedicated piece of software that does the same thing. Eventually languages get their own build system and/or package manager. Perhaps that time has passed, and Fpcupdeluxe is necessary or at least the best solution. Experience has shown me these solutions are inflexible, but Fpcupdeluxe has been around for some time. Perhaps I shouldn't worry.

My comment wasn't about the quality of the code in Fpcupdeluxe.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: DonAlfredo on November 27, 2017, 08:12:09 am
Thanks for explaining !

My advice will always be to follow the official install instruction for FPC and Lazarus.

Fpcupdeluxe is just one of many tools that can help installing FPC and Lazarus.
It can be useful in situations where a standard install fails. Of for something special like cross-compiling.
Most programming efforts has been put into sandboxing an install by fpcupdeluxe and into the [sometimes dark] secrets of cross-compiling and the building of cross-tools.

So, fpcupdeluxe is neither necessary nor the best. But its the best fit in certain situations.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: avra on November 27, 2017, 08:29:06 am
Fpcupdeluxe is just one of many tools that can help installing FPC and Lazarus. It can be useful in situations where a standard install fails. Of for something special like cross-compiling.
+1 for easy cross compilation. I would also mention that it is very usefull to have many FPC/LAZ versions which do not interfere with official ones. I also like when everything is kept in a single directory, so I can easily copy it between computers (it works as long as dir path stays the same - otherwise shortcut needs adjustment).
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on May 10, 2018, 08:43:23 pm
In fact, everything is very simple (tested on Lazarus 1.8.2 with Win32 FPC 3.0.4):
1) Download fpc-3.0.4.i386-linux.tar/download (https://sourceforge.net/projects/freepascal/files/Linux/3.0.4/fpc-3.0.4.i386-linux.tar/download) and unpack it with all attachments.
2) Among the unpacked folders, find "units" (will be here: {unpacked}\lib\fpc\3.0.4).
3) Copy them to Lazurus, to the folder "Lazarus\fpc\3.0.4".
4) Download binutils-2.15-win32-i386-linux.zip (ftp://ftp.freepascal.org/pub/fpc/contrib/cross/mingw/binutils-2.15-win32-i386-linux.zip) (binutils-2.21-win32-x86_64-win64.zip (ftp://ftp.freepascal.org/fpc/contrib/cross/mingw/win64/binutils-2.21-win32-x86_64-win64.zip) for compile x64 app) and unzip.
5) Copy content of "bin" folder to Lazarus ("Lazarus\fpc\3.0.4\i386-win32").
That's all, now in the project parameters it remains to specify "Terget OS: Linux" and "Target CPU: i386".
This scheme allows you to organize any cross-platform compilation, if only there were libraries for the platform (units) and the corresponding cross-compiler (bin).

UPD: In most cases, you just need to download and install the crosscompiler from here: https://www.freepascal.org/download.html
And if there is no suitable compiler, then read on: https://wiki.lazarus.freepascal.org/Cross_compiling
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Thaddy on May 10, 2018, 09:35:26 pm
Yes you are alive and dead at the same time...
Point is that does not always work, fpcdeluxe is the next best thing although I only use it once every release (not even that, but it is good).
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on May 10, 2018, 11:03:00 pm
you are alive and dead at the same time
Oh, yes, this is my invisible essence. :D

The example above will allow novice users to easily navigate in the necessary elements for the IDE, for organizing cross-compilation in general. For specific situations, in any case, an understanding of the principle of work and experience is required.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: rick2691 on May 12, 2018, 03:09:09 pm
@Shrodinger Kater
It seems that the second link...

4) Download ftp://ftp.freepascal.org/fpc/contrib/cross/mingw/binutils-2.15-win32-i386-linux.zip

...has moved to:
ftp://ftp.freepascal.org/pub/fpc/contrib/cross/mingw/binutils-2.15-win32-i386-linux.zip

Rick
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on May 12, 2018, 08:05:32 pm
@rick2691
I guess, you are right. The old link is a redirect and is left for compatibility. Fix the way in the first post, thanks. :D
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Jungle on April 05, 2021, 09:46:37 am
I followed @Schrodinger Kater instructions, but get error when applying new target OS/CPU(err_i386-linux.png)
Do I need to change something in fpc.cfg or somewhere else?

When I try to compile default console project for i386-linux, I get error (compile_error_i386-linux.png). It points me to link.res:161 which is
Code: Pascal  [Select][+][-]
  1. INSERT AFTER .data;
Do I need updated binutils?

When I try to compile default console project for x86_64-linux, I get error (compile_error_x86_64-linux.png)
Do I need x86_64 binutils? And do they exist (I can't access ftp locations now due to restrictions)?

P.S. I have x64 Lazarus 2.0.12 on Windows 10 Pro
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on April 05, 2021, 11:33:47 am
A lot of time was gon since then...
Most likely I can only explain the first message (err_i386-linux.png):
for cross-platform compilation, these directories
 Lazarus\fpc\3.0.4\fpmkinst
 Lazarus\fpc\3.0.4\units
must contain corresponding subdirectories
 i386-linux (Lazarus\fpc\3.0.4\units\i386-linux\rtl\system.ppu)
 i386-win32
 x86_64-win64
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Jungle on April 05, 2021, 12:55:40 pm
\fpmkinst\i386-linux\ contains only *.fpm files
\units\i386-linux\rtl\ does contain system.ppu
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on April 05, 2021, 01:37:49 pm
1) Download fpc-3.0.4.i386-linux.tar/download (https://sourceforge.net/projects/freepascal/files/Linux/3.0.4/fpc-3.0.4.i386-linux.tar/download) and unpack it.
On Windows, this package must be unpacked completely (including binary.i386-linux.tar together with the attached archives) - on Linux it is unpacked automatically.
After that, in "binary.i386-linux" four directories will appear:
 bin
 lib
 man
 share
from the catalog "lib" it is necessary to pick up
 lib\fpc\3.0.4\fpmkinst (contains *.fpm)
 lib\fpc\3.0.4\units (contains system.ppu and others)
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Jungle on April 05, 2021, 01:46:52 pm
Yes, this is exactly what I've done
P.S. The only exception is FPC version (3.2.0)
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on April 05, 2021, 02:14:56 pm
fpc-3.2.0.i386-linux downloaded from here https://www.freepascal.org/down/i386/linux-canada.html (https://www.freepascal.org/down/i386/linux-canada.html), unpacked and checked,
the file is present fpc-3.2.0.i386-linux\binary.i386-linux\lib\fpc\3.2.0\units\i386-linux\rtl\system.ppu
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Jungle on April 05, 2021, 02:23:01 pm
I know the file is here. And I have it in lazarus\fpc\... dir
Anyway I get the above mentioned error
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on April 05, 2021, 02:56:12 pm
A similar error can occur if you uncheck "Use standard compiler config file (fpc.cfg)" in Project Options | Config and Target.
What are your Command line parameters (the "Show Options" button at the bottom of the window) for this configuration?
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Jungle on April 06, 2021, 07:19:43 am
See img
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on April 06, 2021, 09:59:45 am
Yes, there is a problem, but it is related to the new version. It looks like the directory structure has changed. Everything above worked on Lazarus 1.8.2 with FPC 3.0.4. It's a matter of principle to figure it out, but it will take a little more time ::)
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Schrodinger Kater on April 06, 2021, 04:44:34 pm
compile_error_i386-linux.png - working config, answer here: https://www.freepascal.org/faq.html#unix-ld219
simply -X9 in custom project options
and compiled binutils 2.15 are only compatible with win32 FPC
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Jungle on April 06, 2021, 06:38:10 pm
simply -X9 in custom project options
Thanks, will try tomorrow.

compiled binutils 2.15 are only compatible with win32 FPC
Newer binutils mentioned here (https://forum.lazarus.freepascal.org/index.php/topic,15251.msg357869.html#msg357869). But author keeps silence. I've also tried to build it myself but failed due to lack of experience.
Title: Re: How to Lazarus Cross Compile Win32 to Linux ?
Post by: Eternity on April 22, 2021, 08:48:13 pm
compile_error_i386-linux.png - working config, answer here: https://www.freepascal.org/faq.html#unix-ld219
simply -X9 in custom project options
and compiled binutils 2.15 are only compatible with win32 FPC

Thank you very much.
Now it works fine with FPC v3.2.0 Win32.

I have been using v3.0.4 for a long time because of this problem... Finally can have everything updated to latest versions now.
TinyPortal © 2005-2018