* * *

Author Topic: Cross compiling Linux 64 bit to 32 bit.  (Read 9466 times)

chrnobel

  • Full Member
  • ***
  • Posts: 217
Cross compiling Linux 64 bit to 32 bit.
« on: April 10, 2015, 11:40:41 am »
Hi.

I have a freshly installed Linux Mint 17 - 64bit, where I am struggling to get cross compilation to work.

I have installed the latest stable version (2.6.4 and 1.2.6) of Fpc, Fpcsrc, and Lazarus from the .debs.

Default compiling works as expected, no problem.

I then followed the cross compilation Wiki, made the scripts for i386-linux-ld and i386-linux-as, and after installing gcc-multilib I was able to do the "sudo make all CPU_TARGET=i386" and "sudo make crossinstall CPU_TARGET=i386"

Compilation and installation without any problems.

And then, it should be "That's it" according to the Wiki.

BUT apparently that's not it.

I open Lazarus, and want to check if it works:
Project > Options > Compiler Options > Config and Target, sets the target to Linux and the CPU family to i386, and presses test, and gets this:
Code: [Select]
WARNING: library search path does not exist: /opt/gnome/lib
WARNING: unit search path does not exist: /usr/share/lazarus/1.2.6/lcl/units/i386-linux/gtk2
WARNING: unit search path does not exist: /usr/share/lazarus/1.2.6/lcl/units/i386-linux
WARNING: unit search path does not exist: /usr/share/lazarus/1.2.6/components/lazutils/lib/i386-linux
ERROR: compiled FPC unit not found: system.ppu
ERROR: compiled FPC unit not found: sysutils.ppu
ERROR: compiled FPC unit not found: classes.ppu
ERROR: compiled FPC unit not found: avl_tree.ppu
ERROR: compiled FPC unit not found: zstream.ppu


Then I try the "Test cross compiler" example in the cross compilation Wiki:
Code: [Select]
program test;
begin
  writeln('DATE ',{$i %DATE%});
  writeln('FPCTARGET ',{$i %FPCTARGET%});
  writeln('FPCTARGETCPU ',{$i %FPCTARGETCPU%});
  writeln('FPCTARGETOS ',{$i %FPCTARGETOS%});
  writeln('FPCVERSION ',{$i %FPCVERSION%});
end.
"fpc -TLinux -Px86_64 test.pas" works as expected, but

"fpc -TLinux -Pi386 test.pas" ends up with this error:
 
Error: ppc386 can't be executed, error message: Failed to execute "ppc386", error code: 127

I have a feeling that the parts that follows after the laconic "That's it", namely the "Edit your /etc/fpc.cfg file if needed." could as well cover:
"Then you just have to do some mumbo-jumbo"

So what am missing?

Regards
Christian


 

zeljko

  • Hero Member
  • *****
  • Posts: 930
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #1 on: April 10, 2015, 12:32:06 pm »
you're missing ppc386. Maybe it's in /usr/lib/fpc/2.6.0 , so you need to create symlink into /usr/bin ...or where ever, where fpc binary is.

chrnobel

  • Full Member
  • ***
  • Posts: 217
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #2 on: April 10, 2015, 01:00:09 pm »
Thanks, that brought me a step forward - now I can compile the test file, but I do still have a problem in Lazarus.

When trying to test the compile options I get:
Code: [Select]
WARNING: library search path does not exist: /opt/gnome/lib
WARNING: unit search path does not exist: /usr/share/lazarus/1.2.6/lcl/units/i386-linux/gtk2
WARNING: unit search path does not exist: /usr/share/lazarus/1.2.6/lcl/units/i386-linux
WARNING: unit search path does not exist: /usr/share/lazarus/1.2.6/components/lazutils/lib/i386-linux
HINT: using config file /etc/fpc.cfg
ERROR: compiled FPC unit not found: avl_tree.ppu
ERROR: compiled FPC unit not found: zstream.ppu
WARNING: FPC unit path contains a source: /usr/share/fpcsrc/2.6.4/compiler/dbgbase.pas

zeljko

  • Hero Member
  • *****
  • Posts: 930
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #3 on: April 10, 2015, 02:17:20 pm »
That's because lazarus units aren't cross compiled for i386, you must build lazarus with CPU_TARGET=i386 or maybe CPU_TARGET=i686, not sure.

chrnobel

  • Full Member
  • ***
  • Posts: 217
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #4 on: April 10, 2015, 02:55:14 pm »
Tried, and got this result:
Code: [Select]
make -C packager/registration
make[1]: Går til katalog '/usr/share/lazarus/1.2.6/packager/registration'
/bin/rm -f ../units/i386-linux/fcllaz.ppu
/usr/bin/fpc -Pi386 -XPi386-linux- -Xr -MObjFPC -Scghi -O1 -g -gl -vewnhi -l -Fu. -Fu/usr/local/lib/fpc/2.6.4/units/i386-linux/rtl -FE. -FU../units/i386-linux -di386  fcllaz.pas
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.6.4 [2015/04/10] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling fcllaz.pas
Compiling registerfcl.pas
registerfcl.pas(45,22) Fatal: Can't find unit process used by RegisterFCL
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
make[1]: *** [fcllaz.ppu] Fejl 1
make[1]: Forlader katalog '/usr/share/lazarus/1.2.6/packager/registration'
make: *** [registration] Fejl 2

So I am getting closer, but still need to tell fpc/lazarus where/how to find unit process?
« Last Edit: April 10, 2015, 02:57:29 pm by chrnobel »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5826
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #5 on: April 10, 2015, 03:08:56 pm »
This seems to be a problem with the FPC installation. The process unit is part of FPC.

Either the installation is incomplete, or the unit path (-Fu) is not correct.

zeljko

  • Hero Member
  • *****
  • Posts: 930
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #6 on: April 10, 2015, 03:17:34 pm »
I guess that he must tune -Fu in his fpc.cfg for i386 target

chrnobel

  • Full Member
  • ***
  • Posts: 217
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #7 on: April 10, 2015, 03:23:35 pm »
This seems to be a problem with the FPC installation. The process unit is part of FPC.
Either the installation is incomplete
As said, I installed the stable version without problem, and I compiled FPC itself with Target=i386 without any problems.

So how can I determine in which way the installation is incomplete, as everything until Lazarus seems to be ok?

Quote
or the unit path (-Fu) is not correct.
Leading me to - I have made an out-of-the-box installation on a very common Linux, so what do I have to change?

zeljko

  • Hero Member
  • *****
  • Posts: 930
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #8 on: April 10, 2015, 04:05:17 pm »
/etc/fpc.cfg .... there must be entry for i386 -Fu but is probably commented or points to the wrong path

chrnobel

  • Full Member
  • ***
  • Posts: 217
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #9 on: April 10, 2015, 04:15:33 pm »
/etc/fpc.cfg .... there must be entry for i386 -Fu but is probably commented or points to the wrong path

Ok, here comes the fpc.cfg:
Code: [Select]
#
# Config file generated by fpcmkcfg on 10-4-15 - 09:51:33
# Example fpc.cfg for Free Pascal Compiler
#

# ----------------------
# Defines (preprocessor)
# ----------------------

#
# nested #IFNDEF, #IFDEF, #ENDIF, #ELSE, #DEFINE, #UNDEF are allowed
#
# -d is the same as #DEFINE
# -u is the same as #UNDEF
#

#
# Some examples (for switches see below, and the -? helppages)
#
# Try compiling with the -dRELEASE or -dDEBUG on the commandline
#

# For a release compile with optimizes and strip debuginfo
#IFDEF RELEASE
  -O2
  -Xs
  #WRITE Compiling Release Version
#ENDIF

# For a debug version compile with debuginfo and all codegeneration checks on
#IFDEF DEBUG
  -gl
  -Crtoi
  #WRITE Compiling Debug Version
#ENDIF

# assembling
#ifdef darwin
# use pipes instead of temporary files for assembling
-ap
# path to Xcode 4.3+ utilities (no problem if it doesn't exist)
-FD/Applications/Xcode.app/Contents/Developer/usr/bin
#endif

# ----------------
# Parsing switches
# ----------------

# Pascal language mode
#      -Mfpc      free pascal dialect (default)
#      -Mobjfpc   switch some Delphi 2 extensions on
#      -Mdelphi   tries to be Delphi compatible
#      -Mtp       tries to be TP/BP 7.0 compatible
#      -Mgpc      tries to be gpc compatible
#      -Mmacpas   tries to be compatible to the macintosh pascal dialects
#
# Turn on Object Pascal extensions by default
#-Mobjfpc

# Assembler reader mode
#      -Rdefault  use default assembler
#      -Ratt      read AT&T style assembler
#      -Rintel    read Intel style assembler
#
# All assembler blocks are AT&T styled by default
#-Ratt

# Semantic checking
#      -S2        same as -Mobjfpc
#      -Sc        supports operators like C (*=,+=,/= and -=)
#      -Sa        include assertion code.
#      -Sd        same as -Mdelphi
#      -Se<x>     error options. <x> is a combination of the following:
#         <n> : compiler stops after <n> errors (default is 1)
#         w   : compiler stops also after warnings
#         n   : compiler stops also after notes
#         h   : compiler stops also after hints
#      -Sg        allow LABEL and GOTO
#      -Sh        Use ansistrings
#      -Si        support C++ styled INLINE
#      -Sk        load fpcylix unit
#      -SI<x>     set interface style to <x>
#         -SIcom    COM compatible interface (default)
#         -SIcorba  CORBA compatible interface
#      -Sm        support macros like C (global)
#      -So        same as -Mtp
#      -Sp        same as -Mgpc
#      -Ss        constructor name must be init (destructor must be done)
#      -Sx        enable exception keywords (default in Delphi/ObjFPC modes)
#
# Allow goto, inline, C-operators, C-vars
-Sgic

# ---------------
# Code generation
# ---------------

# Uncomment the next line if you always want static/dynamic units by default
# (can be overruled with -CD, -CS at the commandline)
#-CS
#-CD

# Set the default heapsize to 8Mb
#-Ch8000000

# Set default codegeneration checks (iocheck, overflow, range, stack)
#-Ci
#-Co
#-Cr
#-Ct

# Optimizer switches
# -Os        generate smaller code
# -Oa=N      set alignment to N
# -O1        level 1 optimizations (quick optimizations, debuggable)
# -O2        level 2 optimizations (-O1 + optimizations which make debugging more difficult)
# -O3        level 3 optimizations (-O2 + optimizations which also may make the program slower rather than faster)
# -Oo<x>     switch on optimalization x. See fpc -i for possible values
# -OoNO<x>   switch off optimalization x. See fpc -i for possible values
# -Op<x>     set target cpu for optimizing, see fpc -i for possible values

#ifdef darwin
#ifdef cpui386
-Cppentiumm
-Oppentiumm
#endif
#endif

# -----------------------
# Set Filenames and Paths
# -----------------------

# Both slashes and backslashes are allowed in paths

# path to the messagefile, not necessary anymore but can be used to override
# the default language
#-Fr/usr/lib/fpc/$fpcversion/msg/errore.msg
#-Fr/usr/lib/fpc/$fpcversion/msg/errorn.msg
#-Fr/usr/lib/fpc/$fpcversion/msg/errores.msg
#-Fr/usr/lib/fpc/$fpcversion/msg/errord.msg
#-Fr/usr/lib/fpc/$fpcversion/msg/errorr.msg

# searchpath for units and other system dependent things
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl

#IFDEF FPCAPACHE_1_3
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
#ELSE
#IFDEF FPCAPACHE_2_0
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd20
#ELSE
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd22
#ENDIF
#ENDIF

# searchpath for fppkg user-specific packages
-Fu~/.fppkg/lib/fpc/$fpcversion/units/$FPCTARGET/*

# path to the gcclib
#ifdef cpui386
-Fl/usr/lib/gcc/x86_64-linux-gnu/4.8/32
#endif
#ifdef cpux86_64
-Fl/usr/lib/gcc/x86_64-linux-gnu/4.8
#endif

# searchpath for libraries
#-Fl/usr/lib/fpc/$fpcversion/lib
#-Fl/lib;/usr/lib
-Fl/usr/lib/fpc/$fpcversion/lib/$FPCTARGET

# searchpath for tools
-FD/usr/lib/fpc/$fpcversion/bin/$FPCTARGET

#IFNDEF CPUI386
#IFNDEF CPUAMD64
#DEFINE NEEDCROSSBINUTILS
#ENDIF
#ENDIF

#IFNDEF Linux
#DEFINE NEEDCROSSBINUTILS
#ENDIF

# binutils prefix for cross compiling
#IFDEF FPC_CROSSCOMPILING
#IFDEF NEEDCROSSBINUTILS
  -XP$FPCTARGET-
#ENDIF
#ENDIF


# -------------
# Linking
# -------------

# generate always debugging information for GDB (slows down the compiling
# process)
#      -gc        generate checks for pointers
#      -gd        use dbx
#      -gg        use gsym
#      -gh        use heap trace unit (for memory leak debugging)
#      -gl        use line info unit to show more info for backtraces
#      -gv        generates programs tracable with valgrind
#      -gw        generate dwarf debugging info
#
# Enable debuginfo and use the line info unit by default
#-gl

# always pass an option to the linker
#-k-s

# Always strip debuginfo from the executable
-Xs


# -------------
# Miscellaneous
# -------------

# Write always a nice FPC logo ;)
-l

# Verbosity
#      e : Show errors (default)       d : Show debug info
#      w : Show warnings               u : Show unit info
#      n : Show notes                  t : Show tried/used files
#      h : Show hints                  s : Show time stamps
#      i : Show general info           q : Show message numbers
#      l : Show linenumbers            c : Show conditionals
#      a : Show everything             0 : Show nothing (except errors)
#      b : Write file names messages   r : Rhide/GCC compatibility mode
#          with full path              x : Executable info (Win32 only)
#      v : write fpcdebug.txt with     p : Write tree.log with parse tree
#          lots of debugging info
#
# Display Info, Warnings and Notes
-viwn
# If you don't want so much verbosity use
#-vw

This must be a common problem, as I (as said) have made a plain vanilla installation of Linux Mint 17, and a plain vanilla installation of Fpc and Lazarus.

Leledumbo

  • Hero Member
  • *****
  • Posts: 7722
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #10 on: April 10, 2015, 04:17:28 pm »
Code: [Select]
# searchpath for units and other system dependent things
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl

#IFDEF FPCAPACHE_1_3
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
#ELSE
#IFDEF FPCAPACHE_2_0
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd20
#ELSE
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd22
#ENDIF
#ENDIF
None of them points to /usr/local/lib/fpc/...

chrnobel

  • Full Member
  • ***
  • Posts: 217
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #11 on: April 10, 2015, 04:26:46 pm »
None of them points to /usr/local/lib/fpc/...
And could you please enlighten me with what I have to do, not what I failed in doing :)

zeljko

  • Hero Member
  • *****
  • Posts: 930
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #12 on: April 10, 2015, 04:49:50 pm »
Do you have something like this in /etc/fpc.cfg ?
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl

And are your i386 units there ?

chrnobel

  • Full Member
  • ***
  • Posts: 217
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #13 on: April 10, 2015, 05:21:10 pm »
Do you have something like this in /etc/fpc.cfg ?
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl

And are your i386 units there ?
I have added the following 3 lines:

-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

Now I am able to compile Lazarus, but now I face a bizarre problems, as the compilation stops with this error:

Compiling treefilteredit.pas
treefilteredit.pas(61,60) Error: Illegal expression
treefilteredit.pas(61,60) Error: Error in type definition
treefilteredit.pas(61,60) Fatal: Syntax error, ">" expected but "" found
Fatal: Compilation aborted

But line 61 in treefilteredit looks exactly as expected:
Code: [Select]
TBranchList = specialize TFPGObjectList<TTreeFilterBranch>;
and the > is in position 60

very stange :o


Leledumbo

  • Hero Member
  • *****
  • Posts: 7722
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Cross compiling Linux 64 bit to 32 bit.
« Reply #14 on: April 10, 2015, 06:02:53 pm »
Now I am able to compile Lazarus, but now I face a bizarre problems, as the compilation stops with this error:

Compiling treefilteredit.pas
treefilteredit.pas(61,60) Error: Illegal expression
treefilteredit.pas(61,60) Error: Error in type definition
treefilteredit.pas(61,60) Fatal: Syntax error, ">" expected but "" found
Fatal: Compilation aborted

But line 61 in treefilteredit looks exactly as expected:
Code: [Select]
TBranchList = specialize TFPGObjectList<TTreeFilterBranch>;
and the > is in position 60

very stange :o
Guess I've met this bug before. Oh, well, as a fpc trunk user, I never remember when bugs are found and fixed (except those I report myself). Compile now, it bugs, update later, it's gone. If you wish, you can try trunk.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus