How to Lazarus Cross Compile Win32 to Linux ? lazarus / 13-General ---------------------------------------------------------------------- loaded · 2017-05-22 07:18 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. ---------------------------------------------------------------------- avra · 2017-05-22 12:12 Have you tried to download 7z file from the location shown in the 1st screenshot and unpack to your libraries directory? ---------------------------------------------------------------------- loaded · 2017-05-22 12:57 Thanks avra Yes ;  https://www.youtube.com/watch?v=qT9fm0lQA7I watched the video Then I downloaded the file  http://www.pilotlogic.com/codetyphon/libraries/i386-linux.7z ---------------------------------------------------------------------- avra · 2017-05-23 01:09 Well, cross compilers in fpcupdeluxe and codetyphon work out of the box if you check their installation. ---------------------------------------------------------------------- loaded · 2017-05-24 07:35 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. ---------------------------------------------------------------------- DonAlfredo · 2017-05-24 07:49 QuoteI 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 · 2017-05-25 05:25 Thank you for the answer DonAlfredo Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$IFDEF FPC_CROSSCOMPILING}  {$IFDEF LINUX}    {$linklib libc_nonshared.a}  {$ENDIF}{$ENDIF} 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. ---------------------------------------------------------------------- DonAlfredo · 2017-05-25 05:49 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 · 2017-11-25 15:47 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;{$IFDEF FPC_CROSSCOMPILING}  {$IFDEF LINUX}    {$linklib libc_nonshared.a}  {$ENDIF}{$ENDIF}begin  writeln('simple program');  readln;end.Compiler Options: Libraries: {InstallDir}\cross\lib\x86_64-linux\ Target: Linux ---------------------------------------------------------------------- DonAlfredo · 2017-11-25 15:55 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 · 2017-11-25 17:05 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 · 2017-11-25 23:53 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. Quote from: loaded on September 28, 1974, 03:56:34 amNow 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 · 2017-11-26 00:26 Quote from: guest on November 26, 2017, 12:53:02 amThis 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. ---------------------------------------------------------------------- guest60499 · 2017-11-26 01:58 Quote from: molly on November 26, 2017, 01:26:39 amPutting 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 · 2017-11-26 07:35 QuotePersonally I prefer to avoid fpcupdeluxe, it seems odd.I am ok with your opinion, but just out of curiosity: what is odd about it ? ---------------------------------------------------------------------- guest60499 · 2017-11-27 06:48 Quote from: DonAlfredo on November 26, 2017, 08:35:28 amI 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. ---------------------------------------------------------------------- DonAlfredo · 2017-11-27 07:12 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. ---------------------------------------------------------------------- avra · 2017-11-27 07:29 Quote from: DonAlfredo on November 27, 2017, 08:12:09 amFpcupdeluxe 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). ---------------------------------------------------------------------- Schrodinger Kater · 2018-05-10 18:43 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 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 (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 ---------------------------------------------------------------------- Thaddy · 2018-05-10 19:35 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). ---------------------------------------------------------------------- Schrodinger Kater · 2018-05-10 21:03 Quote from: Thaddy on May 10, 2018, 09:35:26 pmyou are alive and dead at the same timeOh, yes, this is my invisible essence. 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. ---------------------------------------------------------------------- rick2691 · 2018-05-12 13:09 @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 ---------------------------------------------------------------------- Schrodinger Kater · 2018-05-12 18:05 @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. ---------------------------------------------------------------------- Jungle · 2021-04-05 07:46 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 ---------------------------------------------------------------------- Schrodinger Kater · 2021-04-05 09:33 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 ---------------------------------------------------------------------- Jungle · 2021-04-05 10:55 \fpmkinst\i386-linux\ contains only *.fpm files \units\i386-linux\rtl\ does contain system.ppu ---------------------------------------------------------------------- Schrodinger Kater · 2021-04-05 11:37 Quote from: Schrodinger Kater on May 10, 2018, 08:43:23 pm1) Download 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) ---------------------------------------------------------------------- Jungle · 2021-04-05 11:46 Yes, this is exactly what I've done P.S. The only exception is FPC version (3.2.0) ---------------------------------------------------------------------- Schrodinger Kater · 2021-04-05 12:14 fpc-3.2.0.i386-linux downloaded from here 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 ---------------------------------------------------------------------- Jungle · 2021-04-05 12:23 I know the file is here. And I have it in lazarus\fpc\... dir Anyway I get the above mentioned error ---------------------------------------------------------------------- Schrodinger Kater · 2021-04-05 12:56 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? ---------------------------------------------------------------------- Jungle · 2021-04-06 05:19 See img ---------------------------------------------------------------------- Schrodinger Kater · 2021-04-06 07:59 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 ---------------------------------------------------------------------- Schrodinger Kater · 2021-04-06 14:44 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 ---------------------------------------------------------------------- Jungle · 2021-04-06 16:38 Quote from: Schrodinger Kater on April 06, 2021, 04:44:34 pmsimply -X9 in custom project optionsThanks, will try tomorrow. Quote from: Schrodinger Kater on April 06, 2021, 04:44:34 pmcompiled binutils 2.15 are only compatible with win32 FPCNewer binutils mentioned here. But author keeps silence. I've also tried to build it myself but failed due to lack of experience. ---------------------------------------------------------------------- Eternity · 2021-04-22 18:48 Quote from: Schrodinger Kater on April 06, 2021, 04:44:34 pmcompile_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.