Configuration for Cross Compiling lazarus / 1-Linux ---------------------------------------------------------------------- BlueMoony · 2015-02-11 14:38 Hello once again, as I am still trying to cross compile from Linux x86-64 to Linux ARM (raspberry Pi), I got another question about how to setup the configuration of FPC. As I followed this tutorial to setup the cross compiler, I stumbled upon a problem in the last step: rebuilding Lazarus for the target CPU. As I select de build configure menu in Tools and set my OS to linux and CPU to arm, it starts to compile/link/.. the lazarus IDE. At at certain point, it fails because it can't find the interfaces.ppu necessary to continue. Now, reading the FAQ about that and reading the error, this is due a wrong version of that file. This is the full error: Code: [Select]Compiling lazarus.pp PPU Loading /home/bjorn/lazarus/lcl/units/arm- linux/gtk2/interfaces.ppu PPU is compiled for another processor lazarus.pp(52,3) Fatal: Can't find unit Interfaces used by Lazarus TExternalToolList.Run Exception: /home/bjorn/lazarus/ide/lazarus.pp(52,3) Fatal: Can't find unit Interfaces used by Lazarus Now, the 'compiled for another processor' is quite strange as right before this error, the following appears: Code: [Select]-Flinclude -Fl/etc/ld.so.conf.d/*.conf @/home/bjorn/.lazarus/idemake.cfg -FU/home/bjorn/.lazarus/units/arm- linux/gtk2 -FE/home/bjorn/.lazarus/bin/arm-linux -o/home/bjorn/.lazarus/bin/arm-linux/lazarus -darm lazarus.pp Free Pascal Compiler version 2.6.4 [2015/02/09] for x86_64 Copyright (c) 1993-2014 by Florian Klaempfl and others Note: Switching assembler to default source writing assembler Target OS: Linux for x86-64 So, why is he switching to x86-64 while he should be doing it for arm? He is definitely in the arm directory... This is my .fpc.cfg file as I changed it a little bit because of other problems: Code: [Select]#INCLUDE /etc/fpc.cfg #DEFINE DEMOTEST #DEFINE DEMOTEST1 #DEFINE LAZARUS -Fu/usr/lib/fpc/2.6.4/units/$fpctarget/* -Fl/usr/lib/fpc/2.6.4/units/$fpctarget/rtl/ -a -Sd -Xd -Xs -O- #IFDEF CPUARM -FD/home/bjorn/lazarus/fpc/binutils/ -Xr/usr/lib/fpc/2.6.4/units/arm-linux/rtl/ -Xr/home/bjorn/lazarus/fpc/libcross -XR/home/bjorn/lazarus/fpc/ -darm -Tlinux #ENDIF It differs from the tutorial on the line Code: [Select]-FD/home/bjorn/lazarus/fpc/binutils/ Is something wrong with my configuration for cross compiling for arm or am I having another problem? Thanks in advance, BlueMoony Additional info: FPC version 2.6.4 Lazarus version 1.2.6 ---------------------------------------------------------------------- Leledumbo · 2015-02-11 15:39 Quote from: BlueMoony on February 11, 2015, 03:38:25 pmNow, the 'compiled for another processor' is quite strange as right before this error, the following appears: Not strange to me: "Target OS: Linux for x86-64" while you're building for arm-linux, certainly something is wrong since you only change the path, but not the compiler. What's the output of: Code: [Select]$ ppudump -vh /home/bjorn/lazarus/lcl/units/arm- linux/gtk2/interfaces.ppu and Code: [Select]$ file /home/bjorn/lazarus/lcl/units/arm- linux/gtk2/interfaces.o ? Quote-Fl/usr/lib/fpc/2.6.4/units/$fpctarget/rtl/ ... -Xr/usr/lib/fpc/2.6.4/units/arm-linux/rtl/Why the hell does the article do this? This doesn't sound right. -Fl and -Xr should not point to unit directory. Moreover, only -XR (should work with -Fl too, I guess) required to point to target device's libs directory. ---------------------------------------------------------------------- BlueMoony · 2015-02-11 18:47 The output of ppudump: Code: [Select]PPU-Analyser Version 2.6.4 Copyright (c) 1998-2013 by the Free Pascal Development Team Analyzing /home/bjorn/lazarus/lcl/units/arm-linux/gtk2/interfaces.ppu (v135) Header ------- Compiler version        : 2.6.4 Target processor        : arm Target operating system : Linux-arm Unit flags              : init, final, static_linked, little_endian, local_threadvars, fpu_emulation_on, has_debug_info, stabs_debug_info, local_symtable FileSize (w/o header)   : 1246 Checksum                : F06238BB Interface Checksum      : 17B6DF52 Indirect Checksum       : 19CF9A0F Definitions stored      : 3 Symbols stored          : 10 Interface symtable ---------------------- Symtable options: none (no exported macros) Implementation symtable ---------------------- Symtable options: none WPO info -------- ** Instantiated Object/Class types: 0 ** ** Instantiated ClassRef types: 0 ** ** Possibly instantiated ClassRef types : 1 ** ** Class types with called virtual methods info : 67 **   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries :   Class def :     Called vmtentries : The output of the file command: Code: [Select]/home/bjorn/lazarus/lcl/units/arm- linux/gtk2/interfaces.o: ELF 32-bit LSB  relocatable, ARM, EABI5 version 1 (SYSV), not stripped The reason I called it strange as it is compiled (well, that is what I think) for an arm processor so 'compiled for another processor' is strange as am I trying to do so for ARM. It is normal when you see that the Target OS is Linux on x86-64 system of course. I was already thinking that something is wrong with the config file. I do not have (yet) copied over the target device's libs as I was waiting for error to pop up like: could not find lpthread and such. Now, do you have any solution or suggestion to get this fixed? ---------------------------------------------------------------------- Leledumbo · 2015-02-12 04:51 QuoteNow, do you have any solution or suggestion to get this fixed?Try building from terminal. Simply call: make all CPU_TARGET=arm in Lazarus dir. Ensure it's ppcrossarm that's called, not ppcx64. ---------------------------------------------------------------------- BlueMoony · 2015-02-12 13:00 Ok, I did that and because he can't find some libraries, I am sure he is using the ppcarm: Code: [Select]/usr/local/bin/arm-linux-ld: cannot find -lpthread /usr/local/bin/arm-linux-ld: cannot find -ldl /usr/local/bin/arm-linux-ld: cannot find -lc lazbuild.lpr(1689) Error: Error while linking lazbuild.lpr(1689) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: /usr/local/bin/ppcarm returned an error exitcode (normal if you did not specify a source file to be compiled) make[2]: *** [lazbuild] Error 1 make[2]: Leaving directory `/home/bjorn/lazarus/ide' make[1]: *** [lazbuilder] Error 2 make[1]: Leaving directory `/home/bjorn/lazarus/ide' make: *** [lazbuild] Error 2 Where should I put those libraries? I've put them in the libcross folder in ~/lazarus/fpc/libcross (for example, there is a file there libpthread.so and a libpthread.a which I copied from the Raspberry Pi) Because of that error, I figured he might search for them in a more standard place so I did: Code: [Select]sudo apt-get install libc6-dev-armhf-crosswhich installed several armhf binaries but still same error Do I have to point the compiler to a specific folder? EDIT: Those files are now also present in /usr/arm-linux-gnueabi/lib/hf as in /usr/arm-linux-gnueabihf/lib ---------------------------------------------------------------------- Leledumbo · 2015-02-12 15:44 Quote from: BlueMoony on February 12, 2015, 02:00:00 pmOk, I did that and because he can't find some libraries, I am sure he is using the ppcarm: Good, that's one step closer. Quote from: BlueMoony on February 12, 2015, 02:00:00 pmWhere should I put those libraries? Anywhere as long as it's accessible and you give a -Fl that points there in your fpc.cfg or via CROSSOPT in make argument. ---------------------------------------------------------------------- BlueMoony · 2015-02-12 16:35 Code: [Select]make all CPU_TARGET=arm CROSSOPT=/usr/arm-linux- gnueabi/lib/hf/or Code: [Select]make all CPU_TARGET=arm CROSSOPT=/home/bjorn/lazarus/fpc/libcross didn't fix it and I can't use the cfg file since well, you know ---------------------------------------------------------------------- Leledumbo · 2015-02-13 07:22 Quote from: BlueMoony on February 12, 2015, 05:35:18 pmCode: [Select]make all CPU_TARGET=arm CROSSOPT=/usr/arm-linux- gnueabi/lib/hf/or Code: [Select]make all CPU_TARGET=arm CROSSOPT=/home/bjorn/lazarus/fpc/libcross didn't fix it and I can't use the cfg file since well, you know make all CPU_TARGET=arm CROSSOPT=-Fl ---------------------------------------------------------------------- BlueMoony · 2015-02-13 11:16 Oh yup, that made it compile further. However, not there yet... Code: [Select]make[1]: Entering directory `/home/bjorn/lazarus/ide' /bin/mkdir -p ../units/arm-linux/gtk2 ../tools/svn2revisioninc .. revision.inc ../tools/svn2revisioninc: 1: ../tools/svn2revisioninc: Syntax error: word unexpected (expecting ")") make[1]: *** [revisioninc] Error 2 make[1]: Leaving directory `/home/bjorn/lazarus/ide' make: *** [ide] Error 2 I thought this might be because of version 1.2.6 of lazarus source, so I tried another source version (1.2.4) but exact same error. Again any suggestions? Edit the revision.inc? EDIT: as it doesn't show any line number (except the 1 which isn't that useful I think), I guess this problem lays in the call to it? ---------------------------------------------------------------------- Leledumbo · 2015-02-13 15:16 Quote from: BlueMoony on February 13, 2015, 12:16:30 pmCode: [Select]../tools/svn2revisioninc: 1: ../tools/svn2revisioninc: Syntax error: word unexpected (expecting ")") Now that's something I never encounter before, svn2revisioninc has always worked for me. Googling a bit, the error seems to come from the shell you're running because tool is executed as a script instead of an executable. Again, please paste the result of: Code: [Select]$ file /tools/svn2revisioninc ---------------------------------------------------------------------- BlueMoony · 2015-02-13 20:05 I have been googling too, no straight solution. Here is the result of file /tools/svn2revisioninc Code: [Select]file tools/svn2revisioninc tools/svn2revisioninc: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.0.0, not stripped Seems how it should be ---------------------------------------------------------------------- Leledumbo · 2015-02-14 03:09 Quote from: BlueMoony on February 13, 2015, 09:05:31 pmI have been googling too, no straight solution. Here is the result of file /tools/svn2revisioninc Code: [Select]file tools/svn2revisioninc tools/svn2revisioninc: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.0.0, not stripped Seems how it should be OK, now try running it. It should output something similar to this: QuoteCreated /path/to/this/dir/revision.inc for revision: and check that the file (revision.inc) really exists containing: Code: [Select]// Created by Svn2RevisionInc const RevisionStr = ''; ---------------------------------------------------------------------- BlueMoony · 2015-02-14 10:51 Quote from: Leledumbo on February 14, 2015, 04:09:42 amQuote from: BlueMoony on February 13, 2015, 09:05:31 pmI have been googling too, no straight solution. Here is the result of file /tools/svn2revisioninc Code: [Select]file tools/svn2revisioninc tools/svn2revisioninc: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.0.0, not stripped Seems how it should be OK, now try running it. It should output something similar to this: QuoteCreated /path/to/this/dir/revision.inc for revision: and check that the file (revision.inc) really exists containing: Code: [Select]// Created by Svn2RevisionInc const RevisionStr = ''; I would like to execute it but it is compiled for ARM so that won't work. Code: [Select]./tools/svn2revisioninc bash: ./tools/svn2revisioninc: cannot execute binary file: Exec format error I didn't run it on the pi, as that has no benefit. However, the file revision.inc doesn't exist in the current folder nor in any folder of lazarus. There are files with names starting with svn2revision and a get_svn_revision_number.sh file. I tried to execute the last file: svnversion not found This was correct because I didn't have subversion installed. After I did, it only showed me a blank line after execution. I also tried to recompile lazarus after installing subversion, no success ---------------------------------------------------------------------- Leledumbo · 2015-02-14 16:41 Quote from: BlueMoony on February 14, 2015, 11:51:50 amI would like to execute it but it is compiled for ARM so that won't work. Ah...so that's it then. I see that it's not possible to cross build Lazarus from a different processor machine without hacking (well, not really, just passing the correct parameter to make) the process. You can add 1 more option when calling make: Code: [Select]make USESVN2REVISIONINC=0You need to generate revision.inc file yourself however (put it in ide directory), since the IDE (lazarus.pp) $I it. I've written the content format above. ---------------------------------------------------------------------- BlueMoony · 2015-02-14 20:11 Ok, you don't need the hacking thingy I think you mean Typing this if somebody else would have the same problem. I just ran a make all, in which case he does run the svn2revisioninc correctly and generates the revision.inc for you. Copied this file to another place and ran the make all with the different parameters (make all CPU_TARGET=arm CROSSOPT=-Fl Of course this pops up the same error again so I copied over the revision.inc file to the /path/to/lazarus/tools/ folder and also in the /path/to/lazarus/ide folder. After this, running the following command Code: [Select]make USESVN2REVISIONINC=0 I guess that fixed the error. I hope this will be my last question: is it possible to point the Fl to multiple directories? My libcross contains all needed files but somehow, when I make Fl point to it, it complains: Code: [Select]/usr/local/bin/arm-linux-ld: cannot find /lib/arm-linux- gnueabihf/libpthread.so.0 /usr/local/bin/arm-linux-ld: cannot find /usr/lib/arm-linux- gnueabihf/libpthread_nonshared.a if I make it point to my the /usr/lib/arm-linux-genueabihf/ folder, it can't find certain libraries (X11,...) So, can I make it point to the 2 folders or should I copy all files from libcross to arm-linux-genueabihf? ---------------------------------------------------------------------- Leledumbo · 2015-02-15 03:05 Quote from: BlueMoony on February 14, 2015, 09:11:14 pmis it possible to point the Fl to multiple directories? No, but you can write multiple -Fl instead, ---------------------------------------------------------------------- BlueMoony · 2015-02-18 16:08 Alright, after not writing multiple -Fl ones (that didn't work somehow), I just symlinked the correct folders and after some hours of fiddling with files, libraries,... it finally compiled! However, the problems are not over yet as in: what was your goal in making it this way? By this, lazarus is compiled for ARM and so my Ubuntu systems isn't able to execute it (wrong binary format)... ---------------------------------------------------------------------- Leledumbo · 2015-02-19 15:03 Quote from: BlueMoony on February 18, 2015, 05:08:03 pmAlright, after not writing multiple -Fl ones (that didn't work somehow), I just symlinked the correct folders and after some hours of fiddling with files, libraries,... it finally compiled! Without looking at how you do it, but my guess is that you didn't properly quote it when passing -Fl through make. This is shell usage problem. Quote from: BlueMoony on February 18, 2015, 05:08:03 pmHowever, the problems are not over yet as in: what was your goal in making it this way? By this, lazarus is compiled for ARM and so my Ubuntu systems isn't able to execute it (wrong binary format)... Now you have it compiled for ARM, you can copy it over a not-so-strong ARM device that may not be capable enough to compile lazarus from source. ---------------------------------------------------------------------- BlueMoony · 2015-02-23 22:52 Thanks for all info and work you put into it! For anybody who is still looking to crosscompile fpc for about anything, just use CodeTyphon. Easy setup, easy use and worked like a charm!