Recent

Author Topic: cross compilation of i386 on amd64 (Ubuntu)  (Read 9215 times)

mm7

  • Full Member
  • ***
  • Posts: 193
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
cross compilation of i386 on amd64 (Ubuntu)
« on: April 24, 2016, 07:31:19 pm »
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_target_on_different_CPUs

Step "Compile FPC: " fails with
Code: Text  [Select][+][-]
  1. root@ubuntu:/usr/share/fpcsrc/3.0.0# make all CPU_TARGET=i386
  2. ...
  3. ...
  4. /bin/mkdir -p i386/units/i386-linux
  5. /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.pas
  6. ld: no input files
  7. pp.pas(247,1) Error: Error while linking
  8. pp.pas(247,1) Fatal: There were 1 errors compiling module, stopping
  9. Fatal: Compilation aborted
  10. make[3]: *** [ppc386] Error 1
  11. make[3]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'
  12. make[2]: *** [cycle] Error 2
  13. make[2]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'
  14. make[1]: *** [compiler_cycle] Error 2
  15. make[1]: Leaving directory `/usr/share/fpcsrc/3.0.0'
  16. make: *** [build-stamp.i386-linux] Error 2
  17.  

I am not sure what is wrong with compiler/pp.pas that ld cannot find some input files.
Please help!
Thanks

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: cross compilation of i386 on amd64 (Ubuntu)
« Reply #1 on: April 24, 2016, 09:24:56 pm »
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

  • Hero Member
  • *****
  • Posts: 583
Re: cross compilation of i386 on amd64 (Ubuntu)
« Reply #2 on: June 07, 2016, 02:31:26 pm »
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][+][-]
  1. /bin/rm -rf x86_64/units
  2. /bin/rm -f x86_64/*.o x86_64/*.ppu x86_64/*.rst x86_64/*.s x86_64/*.a x86_64/*.so x86_64/*.ppl
  3. /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
  4. /bin/rm -f ppc
  5. /bin/mkdir -p x86_64/units/x86_64-linux
  6. /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
  7. /bin/mv -f ./pp ppc
  8. /bin/mv: cannot stat ‘./pp’: No such file or directory
  9. make[3]: *** [ppc] Error 1
  10. make[3]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'
  11. make[2]: *** [cycle] Error 2
  12. make[2]: Leaving directory `/usr/share/fpcsrc/3.0.0/compiler'
  13. make[1]: *** [compiler_cycle] Error 2
  14. make[1]: Leaving directory `/usr/share/fpcsrc/3.0.0'
  15. make: *** [build-stamp.i386-linux] Error 2

Thats the content of ppas.sh:
Code: Diff  [Select][+][-]
  1. #!/bin/sh
  2. DoExitAsm ()
  3. { echo "An error occurred while assembling $1"; exit 1; }
  4. DoExitLink ()
  5. { echo "An error occurred while linking $1"; exit 1; }
  6. echo Linking ./pp
  7. OFS=$IFS
  8. IFS="
  9. "
  10. /usr/bin/ld -b elf64-x86-64 -m elf_x86_64     -s -L. -o ./pp ./link.res
  11. if [ $? != 0 ]; then DoExitLink ./pp; fi
  12. IFS=$OFS
  13.  

Does anyone have an idea how to make cross compiling to Linux i386 work?

Thanks!

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: cross compilation of i386 on amd64 (Ubuntu)
« Reply #3 on: June 07, 2016, 02:49:08 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.
Thats the content of ppas.sh:
The building stops at first step on bootstrapping the compiler, which still generates 64-bit compiler binary.
Does 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

  • Hero Member
  • *****
  • Posts: 583
Re: cross compilation of i386 on amd64 (Ubuntu)
« Reply #4 on: June 07, 2016, 04:28:53 pm »
Thanks for the reply.

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.
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][+][-]
  1. ||/ Name           Version      Architektur  Beschreibung
  2. +++-==============-============-============-=================================
  3. 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

  • Full Member
  • ***
  • Posts: 141
Re: cross compilation of i386 on amd64 (Ubuntu)
« Reply #5 on: June 07, 2016, 11:57:14 pm »
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][+][-]
  1. #!/bin/sh
  2. set -e
  3.  
  4. # create "i386-linux-ld"
  5. if [ ! -e "/usr/bin/i386-linux-ld" ]; then
  6.   sudo touch /usr/bin/i386-linux-ld
  7.   sudo bash -c "echo \#\!/bin/bash >> /usr/bin/i386-linux-ld"
  8.   sudo bash -c 'echo ld -A elf32-i386 \"\$\@\" >> /usr/bin/i386-linux-ld'
  9.   sudo chmod +x /usr/bin/i386-linux-ld
  10. fi
  11.  
  12. # create "i386-linux-as"
  13. if [ ! -e "/usr/bin/i386-linux-as" ]; then
  14.   sudo touch /usr/bin/i386-linux-as
  15.   sudo bash -c "echo \#\!/bin/bash >> /usr/bin/i386-linux-as"
  16.   sudo bash -c 'echo as --32 \"\$\@\" >> /usr/bin/i386-linux-as'
  17.   sudo chmod +x /usr/bin/i386-linux-as
  18. fi
  19.  
  20. # retrieve 32-bit packages
  21. sudo apt-get install gcc-multilib libx11-dev:i386 pixbuf2.0-0:i386 libgtk2.0-0:i386
  22.  
  23. # create missing symlinks
  24. sudo ln -s -f /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so.0 /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so
  25. sudo ln -s -f /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so
  26. sudo ln -s -f /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so
  27. sudo ln -s -f /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 /usr/lib/i386-linux-gnu/libgobject-2.0.so
  28. sudo ln -s -f /lib/i386-linux-gnu/libglib-2.0.so.0 /lib/i386-linux-gnu/libglib-2.0.so
  29. sudo ln -s -f /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 /usr/lib/i386-linux-gnu/libgthread-2.0.so
  30. sudo ln -s -f /usr/lib/i386-linux-gnu/libgmodule-2.0.so.0 /usr/lib/i386-linux-gnu/libgmodule-2.0.so
  31. sudo ln -s -f /usr/lib/i386-linux-gnu/libpango-1.0.so.0 /usr/lib/i386-linux-gnu/libpango-1.0.so
  32. sudo ln -s -f /usr/lib/i386-linux-gnu/libcairo.so.2 /usr/lib/i386-linux-gnu/libcairo.so
  33. sudo 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][+][-]
  1. #!/bin/sh
  2. set -e
  3. cd fpc
  4. make clean all CPU_TARGET=i386 CROSSOPT="-CpPentium -OpPentium -CfX87 -OoFastMath -O3 -XX -CX"
  5. sudo make crossinstall CPU_TARGET=i386
  6. sudo ln -s -f /usr/local/lib/fpc/3.1.1/ppcross386 /usr/local/bin/ppcross386

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: cross compilation of i386 on amd64 (Ubuntu)
« Reply #6 on: June 08, 2016, 01:31:29 pm »
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):
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][+][-]
  1. "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][+][-]
  1. #ifdef i386
  2. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget
  3. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*.
  4. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/rtl
  5. #endif
  6.  
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_compiler
in the shell with
Code: Diff  [Select][+][-]
  1. fpc -Tlinux -Pi386 test.pas
was 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?
« Last Edit: June 08, 2016, 01:43:51 pm by kupferstecher »

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: cross compilation of i386 on amd64 (Ubuntu)
« Reply #7 on: June 08, 2016, 03:25:11 pm »
I got it working!!

The library path to add in the fpc.cfg had two errors. How it's correct:
Code: Diff  [Select][+][-]
  1. #ifdef cpui386
  2. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget
  3. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*
  4. -Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/rtl
  5. #endif
  6.  

Thanks for all for the help!

 

TinyPortal © 2005-2018