Installing Lazarus on Linux to compile in linux, win32 and macOS lazarus / 1-Linux ---------------------------------------------------------------------- plakkies · 2012-09-26 13:05 My first goal was to get Lazarus working just to compile a program for linux. This I found very easy and was able to get this working on every distro I tried. There were a few hicups but the forums and wiki helped out great. My next goal was to get it to compile for Windows. This has been an uphill battle with no end in sight. I referred mainly to http://wiki.freepascal.org/Cross_compiling_for_Win32_under_Linux and I have tried several different distros and versions with varied results but I have not gotten even close to compiling for windows. I have been using a virtual machine with a clean install of whatever distro each time. Has anyone gotten this right? Can I get an image of a VM that someone has got it right in? I have been trying to get this right for over 4 months and Its getting annoying. Is there possibly an ISO with a linux distro that would come with this pre installed? This seems to me like the ideal install, what am I missing? Any help will be highly appreciated. ---------------------------------------------------------------------- plakkies · 2012-10-01 05:54 Come on. There must be someone who has gotten this right. What am I missing? ---------------------------------------------------------------------- BigChimp · 2012-10-01 05:58 See my other post on building a Linux boot cd with cross compile functionality. Somebody probably has this right - but there's no ISO around except for the android cross compiler. If you don't say exactly what you tried and where you failed: 1. how do you think others can help you 2. how can you help improve the documentation? NB: for cross compiling to OSX you will need to copy files from your OSX machines; there's a wiki article on that too. ---------------------------------------------------------------------- Leledumbo · 2012-10-01 07:58 My lin32 can compile for win32 and win64, using that article (and the general cross compiling article) as a base. If you don't say exactly where you failed and what you got so far, it would be difficult to help. Note that as oppose to the article, my installation does NOT use cross binutils, I rely on internal assembler/linker that fpc has for those platforms. So these two are actually the easiest ever. ---------------------------------------------------------------------- plakkies · 2012-10-02 12:40 Thanks for the responses. Ive struggled so much so far I guess an easy answer is not going to happen. To keep this short Ive taken the one install that seems to have taken me the furtherest. This is running on Linux debian 2.6.32-5-686 #1 SMP Sun May 6 04:01:19 UTC 2012 i686 GNU/Linux I have gotten to the point in the guide where I must run 'buildcrosssnaphot.sh' I get the following output lazarus@debian:~/Downloads/binutils-2.22/install/cross$ sh buildcrosssnaphot.sh HOST platform is unknown-linux Building i386-linux i386-linux FAILES Building i386-win32 i386-win32 FAILES [: 133: i386-linux: unexpected operator lazarus@debian:~/Downloads/binutils-2.22/install/cross$ Im not sure what you mean by not using cross binutils. This is probably part of the problem, however many times I read it The whole cross compiling proccess does not make 100% sense to me. I guess if I understood the whole process it would help me to sort it out as well. Thanks again for the help ---------------------------------------------------------------------- TurboRascal · 2012-10-02 13:46 Quote from: Leledumbo on October 01, 2012, 09:58:19 amNote that as oppose to the article, my installation does NOT use cross binutils, I rely on internal assembler/linker that fpc has for those platforms. So these two are actually the easiest ever. That sounds very nice, could you please write some instructions for that setup?  In the existing article or elsewhere... ---------------------------------------------------------------------- Leledumbo · 2012-10-02 15:17 QuoteI have gotten to the point in the guide where I must run 'buildcrosssnaphot.sh'Hmm... I don't use any of those scripts, but seeing your output: Quotelazarus@debian:~/Downloads/binutils-2.22/install/cross$ sh buildcrosssnaphot.shseems like you're executing the script in the wrong directory. buildcrossbinutils should be used at this step (since you're building cross binutils). buildcrosssnaphot should be executed on fpcbuild directory. You can try continuing the process and post further errors here. QuoteThat sounds very nice, could you please write some instructions for that setup?  In the existing article or elsewhere...I'm too lazy to edit the article for now , but here's what I did: Download fpc source (complete one, it should have compiler directory instead of just packages and rtl)for win32, cd to rtl and execute: make all OS_TARGET=win32 && sudo make crossinstall OS_TARGET=win32 INSTALL_PREFIX=/usr then cd to packages and repeat the command (same arch doesn't require different compiler) for win64, cd to the top directory and execute: make all OS_TARGET=win64 CPU_TARGET=x86_64 && sudo make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=/usrNote that above INSTALL_PREFIX assume fpc lib to be in /usr/lib/fpc. After installing, don't forget to create symlink to /usr/lib/fpc//ppcrossx64 in /usr/bin (if you have fpc binaries there). I have self-built script to maintain all my fpc targets when I update from svn (currently I target i386-linux, i386-win32, x86_64-win64, arm-linux, jvm-java and jvm-android). ---------------------------------------------------------------------- plakkies · 2012-10-03 07:40 @Leledumbo Can I assume you use arch linux? I will then use a clean arch install and start from scratch. just to make sure Ive done everything right and use the latest versions. ---------------------------------------------------------------------- Leledumbo · 2012-10-03 12:10 QuoteCan I assume you use arch linux?No, I use Kubuntu. But I don't take neither fpc nor lazarus from repository, everything is built from source (svn), except for fpc stable version (for bootstrapping in case current revision can't be compiled with previous one I have). ---------------------------------------------------------------------- TurboRascal · 2012-10-04 16:53 Quote from: Leledumbo on October 02, 2012, 05:17:24 pmI'm too lazy to edit the article for now , but here's what I did: Thanks I might put that on wiki if I find the time. So far I've put it on my ToDo list on the wiki. Perhaps someone does that even sooner ---------------------------------------------------------------------- plakkies · 2012-10-10 11:16 Its been a while , it seems I have all the luck. took me a while to get kubuntu running. I guess with all the issues I find I can only learn more. Ive gotten the furtherest Ive been so far. I did the following Installed kubuntu in a VM with guest additions (took way longer than I though) Followed http://wiki.freepascal.org/Cross_compiling_for_Win32_under_Linux I had a problem with "BINUTILSPATH=~/download/" as my download folder was "Downloads" I changed the value in the file to be appropriate, this was a bad idea, lots of errors. Changing the Downloads folder to download solved plenty of errors. When I got to the part about changing the fpc.cfg file I realised I needed to install lazarus in the first place. I proceeded to do this. Then I changed the fpc.cfg file The next step shows to go to the Lazarus directory(i dont know where this is) or to do a few things in the IDE. When I do those things in the IDE I get the following two errors one after the other. The project uses target OS=win32 and CPU=i386. The system.ppu for this target was not found in the FPC binary directories. Make sure fpc is installed correctly for this target and the fpc.cfg contains the right directories. and This set of options to build Lazarus is not supported by this installation. The directory "/usr/lib/lazarus/0.9.30.2/lcl" is not writable. See the Lazarus website for other ways to install Lazarus. Any ideas? btw I love that I can copy and paste dialog boxes in linux, you cant do that in windows ---------------------------------------------------------------------- plakkies · 2012-10-10 14:17 Update: I chowned /usr/lib/lazarus second error is gone now.  First error is still there ---------------------------------------------------------------------- Leledumbo · 2012-10-10 14:51 QuoteThe project uses target OS=win32 and CPU=i386. The system.ppu for this target was not found in the FPC binary directories. Clear enough, I guess. Do you have /units/i386-win32 besides i386-linux? And if you do, make sure it has all i386-win32 rtl units (and all other units you needed). And if you're sure they're all there, post -Fu lines in your fpc.cfg. ---------------------------------------------------------------------- plakkies · 2012-10-11 04:46 Ok The only place I find i386-win32 is /usr/lib/lazarus/0.9.30.2/lcl/units/i386-win32 is that the right place? Im not too sure about that one. Is this the part of fpc.cfg you wanted? #IFDEF win32 -Fu~/cross_fpc/lib/fpc/$fpcversion/cross/units/i386-win32/ -Fu~/cross_fpc/lib/fpc/$fpcversion/cross/units/i386-win32/* -Fu~/cross_fpc/lib/fpc/$fpcversion/cross/units/i386-win32/rtl -XPi686-mingw32- -FD~/cross_fpc/cross/bin #ELSE linux -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/* -Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl #-Fu~/fpc/packages/*;~/fpc/rtl/linux #ENDIF and now that I've looked at the above I checked and I see that ~/cross_fpc/lib/fpc/ does not exist. ~/cross_fpc/lib exists and there are plenty other things there as well. Could this have something to do with me installing lazarus at the wrong stage? Thanks for all the help ---------------------------------------------------------------------- Leledumbo · 2012-10-11 09:20 QuoteThe only place I find i386-win32 is /usr/lib/lazarus/0.9.30.2/lcl/units/i386-win32 is that the right place? Im not too sure about that one.No, I'm asking about FPC. So, if your normal FPC is in /usr/lib/fpc, normally you would have /usr/lib/fpc//units/i386-linux containing rtl and packages units. In my installation, and since it's possible (so I don't need to ifdef my fpc.cfg), I also have /usr/lib/fpc//units/i386-win32 for win32 cross compilation. In case you want to use different directory, feel free but your fpc.cfg would contain ifdef then. QuoteIs this the part of fpc.cfg you wanted?Yes, and apparently you already have the ifdef. Normally, you only need 1 -Fu, and it should point to directory above + wildcard (e.g. /usr/lib/fpc//units/i386-win32/*) because below every directory under i386-win32 are where the .ppu and .o lie, and this is where -Fu should point. The -XP and -FD is not really required since by default win32 target will use internal assembler and linker, but it's OK to have. Quote~/cross_fpc/lib exists and there are plenty other things there as well. Could this have something to do with me installing lazarus at the wrong stage?I guess not, just some wrong paths, correct it to yours. Just remember the structure above, it should be the same for any target as long as the host is linux. I think I'll create an article to setup a cross compilation environment on linux for any target. ---------------------------------------------------------------------- plakkies · 2012-10-11 13:47 Ok so the problem seems to be that I dont have the relevant i386-win32 then for FPC. Once I have that I can make sure the path is correct for that. So the question is where do I get this i386-win32, is it the same one as Lazarus or do I build it somehow? Thanks again for all the help. btw when I finally get this working does anyone know where I can put this kubuntu snapshot so that others can benefit? ---------------------------------------------------------------------- Leledumbo · 2012-10-11 15:00 QuoteSo the question is where do I get this i386-win32, is it the same one as Lazarus or do I build it somehow?No, you should've built it, you did follow the wiki, right? That doing make OS_TARGET=win32 blablabla in a directory containing FPC sources... ---------------------------------------------------------------------- plakkies · 2012-10-22 07:28 I think I might be loosing it. How do I miss out a whole section. I missed the "Cross build FPC" section in my run through. I might be doing too many things at once. OK so new problem. When I do this section it looks like it cant find the source. I downloaded the source from http://sourceforge.net/projects/freepascal/files/Source/2.6.0/ as per the instructions. Did I get it from the right place? I was a bit confused when looking for it. I also had to change the location in the setup file of the source to include the version as that how it unzipped. Oh and its been hectic here had to take a trip to Swaziland on business. I need to convince management to get another programmer I think. ---------------------------------------------------------------------- Leledumbo · 2012-10-22 11:15 OK, hang in there, I'm tidying up my automatic cross build script so it can be used by everybody. ---------------------------------------------------------------------- plakkies · 2012-10-23 13:35 Awesome, Thanks I'll be patient. ---------------------------------------------------------------------- Leledumbo · 2012-10-23 17:05 Not thoroughly tested, but seems working fine. The script must be placed in the same place as fpc source folder. e.g. if you put it in ~/Sources/build-fpc-cross-all.sh then there should also be ~/Sources/fpc containing the full fpc source (directories: compiler, rtl, packages, utils, etc.). Feel free to modify the script according to your needs (bash >4.0 skill required). The script also assumes everything from fpc.cfg (e.g. the cross assembler and linker depends on whatever settings set in fpc.cfg). ---------------------------------------------------------------------- plakkies · 2012-10-24 10:15 Did I screw something up? kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ sh ./build-fpc- cross-all.sh ./build-fpc-cross-all.sh: 11: ./build-fpc-cross-all.sh: Syntax error: "(" unexpected kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ Am I in the right place? kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ ls build-fpc-cross-all.sh  compiler   ide        Makefile      packages  tests build-stamp.i386-win32  fpc-2.6.0  installer  Makefile.fpc  rtl       utils kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ ---------------------------------------------------------------------- Leledumbo · 2012-10-24 13:07 QuoteDid I screw something up?Hmm... your bash version? Try breaking down the associative array initialization, change: Code: [Select]declare -A targets=(   [i386-linux]="$nativeopt"   [i386-win32]="$crossopt"   [x86_64-win64]="$crossopt"   [arm-linux]="CROSSOPT='$stdopt -dFPC_ARMEL'"   [jvm-java]="$crossopt ALLOW_WARNINGS=1"   [jvm-android]="$crossopt ALLOW_WARNINGS=1" )to: Code: [Select]declare -A targets targets=(   [i386-linux]="$nativeopt"   [i386-win32]="$crossopt"   [x86_64-win64]="$crossopt"   [arm-linux]="CROSSOPT='$stdopt -dFPC_ARMEL'"   [jvm-java]="$crossopt ALLOW_WARNINGS=1"   [jvm-android]="$crossopt ALLOW_WARNINGS=1" )or: Code: [Select]declare -A targets targets[i386-linux]="$nativeopt" targets[i386-win32]="$crossopt" targets[x86_64-win64]="$crossopt" targets[arm-linux]="CROSSOPT='$stdopt -dFPC_ARMEL'" targets[jvm-java]="$crossopt ALLOW_WARNINGS=1" targets[jvm-android]="$crossopt ALLOW_WARNINGS=1" QuoteAm I in the right place?No, go 1 directory above. ---------------------------------------------------------------------- plakkies · 2012-10-24 14:08 Regarding bash version kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ bash -version bash -version GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ here are the results of the two changes. kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ sh ./build-fpc- cross-allA.sh ./build-fpc-cross-allA.sh: 11: ./build-fpc-cross-allA.sh: declare: not found ./build-fpc-cross-allA.sh: 12: ./build-fpc-cross-allA.sh: Syntax error: "(" unexpected kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ sh ./build-fpc- cross-allB.sh ./build-fpc-cross-allB.sh: 11: ./build-fpc-cross-allB.sh: declare: not found ./build-fpc-cross-allB.sh: 12: ./build-fpc-cross-allB.sh: targets[i386-linux]=OPT=$stdopt: not found ./build-fpc-cross-allB.sh: 13: ./build-fpc-cross-allB.sh: targets[i386-win32]=CROSSOPT=$stdopt: not found ./build-fpc-cross-allB.sh: 14: ./build-fpc-cross-allB.sh: targets[x86_64-win64]=CROSSOPT=$stdopt: not found ./build-fpc-cross-allB.sh: 15: ./build-fpc-cross-allB.sh: targets[arm- linux]=CROSSOPT='-g- -CX -XXs -O3 -dFPC_ARMEL': not found ./build-fpc-cross-allB.sh: 16: ./build-fpc-cross-allB.sh: targets[jvm- java]=CROSSOPT=$stdopt ALLOW_WARNINGS=1: not found ./build-fpc-cross-allB.sh: 17: ./build-fpc-cross-allB.sh: targets[jvm- android]=CROSSOPT=$stdopt ALLOW_WARNINGS=1: not found ./build-fpc-cross-allB.sh: 20: cd: can't cd to fpc ./build-fpc-cross-allB.sh: 22: ./build-fpc-cross-allB.sh: Bad substitution kubuntu@kubuntu-VirtualBox:~/sources/fpc/fpc-2.6.0$ There is only one folder in ~/sources/fpc  Should I move everything from fpc-2.6.0 there and run from there instead? Thanks again for all the help ---------------------------------------------------------------------- marcov · 2012-10-24 19:13 So the end conclusion is that "sh" apparantly isn't "bash". So try bash ./thescript.sh ---------------------------------------------------------------------- BigChimp · 2012-10-24 20:04 Or just Code: [Select]chmod u+x ./build-fpc-cross-allA.sh once and subsequently Code: [Select]./build-fpc-cross-allA.sh Edit: 25 Oct: oops typo: chmod u+x /build... => chmod u+x ./build, formatting ---------------------------------------------------------------------- plakkies · 2012-10-25 07:55 Just goes to show how much experience I have. I guess Im learning plenty which is good. Bash/sh, same thing to me apparently. I was able to run the script. It showed way too much stuff to keep track of and took a while, I did not notice any errors. I now have the i386-win32 folder in the right place I think with the rtl files in the right directory. But Im still stuck at this stage The next step shows to go to the Lazarus directory(i dont know where this is) or to do a few things in the IDE. When I do those things in the IDE I get the following error. The project uses target OS=win32 and CPU=i386. The system.ppu for this target was not found in the FPC binary directories. Make sure fpc is installed correctly for this target and the fpc.cfg contains the right directories. I did some checking and double checking, to make sure nothing was misspelled. In the process and by mistake I see that Lazarus is using FPC version 2.4 instead of 2.6 which is where all the files are. I think the solution would be to get Lazarus to use FPV V2.6. Im not sure how to do this. I thought 2.6 was installed. ---------------------------------------------------------------------- Leledumbo · 2012-10-25 15:28 QuoteI did some checking and double checking, to make sure nothing was misspelled. In the process and by mistake I see that Lazarus is using FPC version 2.4 instead of 2.6 which is where all the files are. I think the solution would be to get Lazarus to use FPV V2.6. Im not sure how to do this. I thought 2.6 was installed.Check your symlinks, make sure they point to the correct version of ppcXXX. ---------------------------------------------------------------------- Dibo · 2012-10-25 15:53 Nobody mentioned about Code Typhon in this topic. I'm using it from a couple months and I'm just impressed with build-in cross-compiling support. Those boys did realy good work. Configuration is so easy. Too bad that Lazarus don't provide such version (I mean, installator with cross-compile support, big IDE from CT is not important for me). I tried configure normal lazarus to cross-compile couple of times referring to wiki page, but I always fail. Wiki content about cross- compile is illegible (too much sublinks to other articles). Since I meet Code Typhon, Lazarus is really cross-compile environment for me, previously I used virtualbox for each OS ---------------------------------------------------------------------- Leledumbo · 2012-10-25 17:33 Hold on, I think I make some mistakes regarding the quotes. Anybody with Bash skill could help to fix? ---------------------------------------------------------------------- Leledumbo · 2012-10-26 05:03 I come up with another solution, this time it's tested thoroughly and works* *) at least here, hope on yours too. still, in case, anybody have decent bash knowledge, feel free to modify the script to be better, this quoting stuff makes me UPDATE: Fix a little so that OPT is used instead of CROSSOPT for cpu target same as host ---------------------------------------------------------------------- BigChimp · 2012-10-26 06:28 Thanks leledumbo, had a look at the original script and it turns out I'm definitely not a bash guru - no ideas at all about what to change. One more reason to get more cross compiler support into fpcup ---------------------------------------------------------------------- plakkies · 2012-10-26 11:45 I ran that script, don't see a difference. It runs and no visible errors. Not sure of the next step. but I'm sure there must be one. If I compile some test code it compiles and runs but I can only find a binary for my system. Im thinking I have to run the step I mentioned in my last post but I still get the same error. The FPCv2.4.4 is also still bugging me. Im sure the about screen should show V2.6. I have no idea how to make this happen as I though I had installed v2.6. I dont know where the v2.4.4 comes from ---------------------------------------------------------------------- Leledumbo · 2012-10-26 13:12 QuoteI ran that script, don't see a difference. It runs and no visible errors. The problem is in my system then, somehow bash lost the variable passed to make. That's why I modify the code to be somewhat redundant, but totally works. If the previous script works for you, good then. QuoteNot sure of the next step. but I'm sure there must be one. If I compile some test code it compiles and runs but I can only find a binary for my system.Add -T and -P parameters depending on your target. QuoteThe FPCv2.4.4 is also still bugging me. Im sure the about screen should show V2.6. I have no idea how to make this happen as I though I had installed v2.6. I dont know where the v2.4.4 comes fromAs I said earlier: check your symlinks. ---------------------------------------------------------------------- plakkies · 2012-10-29 04:58 Where do I add the -T and -P paramitors? Sorry I did not see your original post about the symlinks. Where do I find this? Thanks again for all the help guys. Oh and I did try Typhoon It does not work in linux as far as I can see and when I tried in widows I could not get it to work either. Id rather have as little to do with windows as possible. ---------------------------------------------------------------------- plakkies · 2012-10-30 12:26 Just noticed the first instruction in the wiki  []$ cd ~  []$ svn co http://svn.freepascal.org/svn/fpcbuild/branches/fixes_2_4/install install Should that not be fixes_2_6 ??? ---------------------------------------------------------------------- Leledumbo · 2012-10-30 15:44 QuoteWhere do I add the -T and -P paramitors?Compiler Options->Code Generation->Target Platform QuoteSorry I did not see your original post about the symlinks. Where do I find this? execute in terminal: ls -l /usr/bin/ppc*