cross compilation of i386 on amd64 (Ubuntu) lazarus / 32-Linux ---------------------------------------------------------------------- mm7 · 2016-04-24 17:31 Hi, I have Lazarus 1.6.0 and FPC 3.0.0 installed. Currently application has been compiled and build for amd64. I need to build application in both architectures i386 and amd64. I am following http://wiki.freepascal.org/Cross_compiling#Host_and_tar get_on_different_CPUs Step "Compile FPC: " fails with Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i root@ubuntu:/usr/share/fpcsrc/3.0.0# make all CPU_TARGET=i386....../bin/mkdir -p i386/units/i386-linux/usr/share/fpcsrc/3.0.0/compiler/ppcross386 -Pi386 -XPi386-linux- -Xr -Ur -Xs -O2 -n -Fui386 -Fusystems -Fu/usr/share/fpcsrc/3.0.0/rtl/units/i386-linux -Fii386 -FE. -FUi386/units/i386-linux -dRELEASE -di386 -dGDB -dBROWSERLOG -Fux86 -Sew    -di386 -dGDB -dBROWSERLOG -Fux86 -Sew pp.pasld: no input filespp.pas(247,1) Error: Error while linkingpp.pas(247,1) Fatal: There were 1 errors compiling module, stoppingFatal: Compilation abortedmake[3]: *** [ppc386] Error 1make[3]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'make[2]: *** [cycle] Error 2make[2]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'make[1]: *** [compiler_cycle] Error 2make[1]: Leaving directory `/usr/share/fpcsrc/3.0.0'make: *** [build-stamp.i386-linux] Error 2  I am not sure what is wrong with compiler/pp.pas that ld cannot find some input files. Please help! Thanks ---------------------------------------------------------------------- marcov · 2016-04-24 19:24 Try adding OPT='-s',  then it will not link, and you can check ppas.sh how it is called. Increasing verbosity can also help. It might be that a x86_64 linker is called that rejects all generated 32-bit .o files, and then concludes it has no (x86_64) files. ---------------------------------------------------------------------- kupferstecher · 2016-06-07 12:31 I have the same issue on Linuxmint 64 bit. "sudo make all CPU_TARGET=i386" leads to the linking error described by the TE. A Make with CPU-Target Win64 is working: "sudo make all OS_TARGET=win64 CPU_TARGET=x86_64" also Win32 is working: "sudo make all OS_TARGET=win32 CPU_TARGET=i386" I tried the suggestion by marcov, adding OPT='-s', the command then looks like this: "sudo make all OPT='-s' CPU_TARGET=i386" Now it leads to the following Errors: Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /bin/rm -rf x86_64/units/bin/rm -f x86_64/*.o x86_64/*.ppu x86_64/*.rst x86_64/*.s x86_64/*.a x86_64/*.so x86_64/*.ppl/bin/rm -f x86_64/ppc386 x86_64/ppc68k x86_64/ppcx64 x86_64/ppcppc x86_64/ppcsparc x86_64/ppcppc64 x86_64/ppcarm x86_64/ppcmips x86_64/ppcmipsel x86_64/ppcjvm x86_64/ppc8086 x86_64/ppc/bin/rm -f ppc/bin/mkdir -p x86_64/units/x86_64-linux/usr/bin/ppcx64 -Ur -Xs -O2 -n -Fux86_64 -Fusystems -Fu/usr/share/fpcsrc/3.0.0/rtl/units/x86_64-linux -Fix86_64 -FE. -FUx86_64/units/x86_64-linux -Cg -dRELEASE -s   -dx86_64 -dGDB -dBROWSERLOG -Fux86 -Sew pp.pas/bin/mv -f ./pp ppc/bin/mv: cannot stat ‘./pp’: No such file or directorymake[3]: *** [ppc] Error 1make[3]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'make[2]: *** [cycle] Error 2make[2]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'make[1]: *** [compiler_cycle] Error 2make[1]: Leaving directory `/usr/share/fpcsrc/3.0.0'make: *** [build- stamp.i386-linux] Error 2 Thats the content of ppas.sh: Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #!/bin/shDoExitAsm (){ echo "An error occurred while assembling $1"; exit 1; }DoExitLink (){ echo "An error occurred while linking $1"; exit 1; }echo Linking ./ppOFS=$IFSIFS=""/usr/bin/ld -b elf64-x86-64 -m elf_x86_64     -s -L. -o ./pp ./link.resif [ $? != 0 ]; then DoExitLink ./pp; fiIFS=$OFS  Does anyone have an idea how to make cross compiling to Linux i386 work? Thanks! ---------------------------------------------------------------------- Leledumbo · 2016-06-07 12:49 Quote from: kupferstecher on June 07, 2016, 02:31:26 pm/usr/bin/ppcx64 -Ur -Xs -O2 -n -Fux86_64 -Fusystems -Fu/usr/share/fpcsrc/3.0.0/rtl/units/x86_64-linux -Fix86_64 -FE. -FUx86_64/units/x86_64-linux -Cg -dRELEASE -s   -dx86_64 -dGDB -dBROWSERLOG -Fux86 -Sew pp.pas /bin/mv -f ./pp ppc /bin/mv: cannot stat ‘./pp’: No such file or directory Adding -s will not call assembler and linker (see `fpc -h` output), hence the compiler binary won't be generated. Quote from: kupferstecher on June 07, 2016, 02:31:26 pmThats the content of ppas.sh: The building stops at first step on bootstrapping the compiler, which still generates 64-bit compiler binary. Quote from: kupferstecher on June 07, 2016, 02:31:26 pmDoes anyone have an idea how to make cross compiling to Linux i386 work? Check if your binutils have 32-bit cross compiling support. If yes, check your fpc.cfg. Make sure it has -Fl lines pointing to your i386 libraries, add -Xd if necessary to avoid searching libraries in 64-bit path, put it between #IFDEF FPC_CROSSCOMPILING and #ENDIF lines so it will be passed only when cross compiling. If all are fulfilled, the make parameters are similar as for win32/win64. ---------------------------------------------------------------------- kupferstecher · 2016-06-07 14:28 Thanks for the reply. Quote from: Leledumbo on June 07, 2016, 02:49:08 pmCheck if your binutils have 32-bit cross compiling support. If yes, check your fpc.cfg. Make sure it has -Fl lines pointing to your i386 libraries, add -Xd if necessary to avoid searching libraries in 64-bit path, put it between #IFDEF FPC_CROSSCOMPILING and #ENDIF lines so it will be passed only when cross compiling. If all are fulfilled, the make parameters are similar as for win32/win64. So the '-s' compilation is not needed? I'm new to Linux, so I can't follow your steps. I tried to find binutils on the system, all I found was this (using command "dpkg -l binutils"): Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ||/ Name         Version      Architektur  Beschreibung+++-==============- ============-============-=================================ii  binutils       2.24-5ubuntu amd64        GNU assembler, linker and binary What I read from the internet it seems that the cross compiling capability of the binutils has to be defined while compilation (of them). Also which libraries are needed and refered to in fpc.cfg I have no idea:-( ---------------------------------------------------------------------- ykot · 2016-06-07 21:57 I'm using the following two scripts, which build i386 target of FPC trunk and then Lazarus trunk (which is why it downloads some packages and creates missing symlinks): fpc-prepare-x32.sh  Before running this, make sure to remove existing "/usr/bin/i386-linux-ld" and "/usr/bin/i386-linux-as". Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #!/bin/shset -e # create "i386-linux-ld"if [ ! -e "/usr/bin/i386-linux-ld" ]; then  sudo touch /usr/bin/i386-linux-ld  sudo bash -c "echo \#\!/bin/bash >> /usr/bin/i386-linux-ld"  sudo bash -c 'echo ld -A elf32-i386 \"\$\@\" >> /usr/bin/i386-linux-ld'  sudo chmod +x /usr/bin/i386-linux-ldfi # create "i386-linux-as"if [ ! -e "/usr/bin/i386-linux-as" ]; then  sudo touch /usr/bin/i386-linux-as  sudo bash -c "echo \#\!/bin/bash >> /usr/bin/i386-linux-as"  sudo bash -c 'echo as --32 \"\$\@\" >> /usr/bin/i386-linux-as'  sudo chmod +x /usr/bin/i386-linux-asfi # retrieve 32-bit packagessudo apt-get install gcc-multilib libx11-dev:i386 pixbuf2.0-0:i386 libgtk2.0-0:i386 # create missing symlinkssudo ln -s -f /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so.0 /usr/lib/i386-linux- gnu/libgdk_pixbuf-2.0.sosudo ln -s -f /usr/lib/i386-linux- gnu/libgtk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgtk-x11-2.0.sosudo ln -s -f /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgdk-x11-2.0.sosudo ln -s -f /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 /usr/lib/i386-linux- gnu/libgobject-2.0.sosudo ln -s -f /lib/i386-linux- gnu/libglib-2.0.so.0 /lib/i386-linux-gnu/libglib-2.0.sosudo ln -s -f /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 /usr/lib/i386-linux- gnu/libgthread-2.0.sosudo ln -s -f /usr/lib/i386-linux- gnu/libgmodule-2.0.so.0 /usr/lib/i386-linux-gnu/libgmodule-2.0.sosudo ln -s -f /usr/lib/i386-linux-gnu/libpango-1.0.so.0 /usr/lib/i386-linux-gnu/libpango-1.0.sosudo ln -s -f /usr/lib/i386-linux-gnu/libcairo.so.2 /usr/lib/i386-linux- gnu/libcairo.sosudo ln -s -f /usr/lib/i386-linux-gnu/libatk-1.0.so.0 /usr/lib/i386-linux-gnu/libatk-1.0.so fpc-build-x32.sh  The following script assumes it is in some folder, which has "fpc" subfolder, where FPC code is located. You may change "cd fpc" command, if it's different on your machine. Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #!/bin/shset -ecd fpcmake clean all CPU_TARGET=i386 CROSSOPT="-CpPentium -OpPentium -CfX87 -OoFastMath -O3 -XX -CX"sudo make crossinstall CPU_TARGET=i386sudo ln -s -f /usr/local/lib/fpc/3.1.1/ppcross386 /usr/local/bin/ppcross386 ---------------------------------------------------------------------- kupferstecher · 2016-06-08 11:31 Quote from: ykot on June 07, 2016, 11:57:14 pmI'm using the following two scripts, which build i386 target of FPC trunk and then Lazarus trunk (which is why it downloads some packages and creates missing symlinks): Thanks, that brought me one step further, but its not working in Lazarus, yet. After running the fpc-prepare-x32.sh script, compilation with "sudo make clean all CPU_TARGET=i386" was successful and also the fpc- build-x32.sh script went through smoothly. Unfortunately, Lazarus still prompted the message : Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i "Compiler "/usr/bin/fpc" does not support target" I tried some steps according this thread: http://forum.lazarus.freepascal.org/index.php/topic,28012.0.html I.e., added these lines in /usr/fpc.cfg: Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #ifdef i386-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget-Fu/usr/local/li b/fpc/$fpcversion/units/$fpctarget/*.- Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/rtl#endif ppc386 was missing in /usr/lib/fpc/3.0.0, so the symlink in /usr/bin was without target. I found ppc386 in the fpcsrc folder under /usr/share/fpcsrc/3.0.0/compiler and created a symlink in /usr/bin to there (Perhaps thats the wrong way to do it?). Compiling the test program  http://wiki.lazarus.freepascal.org/Cross_compiling#Test_cross_compile r in the shell with Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -Tlinux -Pi386 test.paswas successful and possible to run! When opening Lazarus the message "Compiler "/usr/bin/fpc" does not support target" was not shown anymore -> good! When I tried to compile it stopped with the message: "Cant find process used by RegisterFCL of package FCL." I guess that has something to do with the missing ppc386 file in /usr/lib/fpc/3.0.0? Thanks for help! PS: The script fpc-prepare-x32.sh seems not to download FPC and Lazarus. To run the second script I copied the folder /usr/share/fpcsrc/3.0.0 to a desktop-folder and renamed it to fpc to run the script fpc-build-x32.sh. fpc and fpc-src were installed by this time. EDIT: I found a file named ppcross386 in /usr/local/lib/fpc/3.0.0/. Is there a relation to ppc386? ---------------------------------------------------------------------- kupferstecher · 2016-06-08 13:25 I got it working!! The library path to add in the fpc.cfg had two errors. How it's correct: Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #ifdef cpui386-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget-Fu/usr/local /lib/fpc/$fpcversion/units/$fpctarget/*- Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/rtl#endif  Thanks for all for the help!