Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-11

cross compiling x64_64 to i386 linux

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Seth Grover

I'm trying to cross-compile on Ubuntu 9.10 x86_64 for i386. Here's what I've done so far:

I got FPC from the fixes_2_4 branch in SVN and did make/make install.

I used samplecfg to generate /etc/fpc/fpc.cfg.

I followed the wiki
(http://wiki.lazarus.freepascal.org/Cross_compiling#To_Linux) and did the steps listed there, including creating the i386-linux-ld and i386-linux-ls scripts in /usr/bin and compiling for the i386 target, so I ended up with a ppc386.

At this point I could do a simple "hello world" program which would generate a 64-bit binary if i selected x86_64 for the target in lazarus under "Compiler Options | Code" and a 32-bit binary if i selected i386 as the target. So far so good.

I then tried to compile something a bit more complicated (not that much more, though: I just tried to include "cthreads") and I got an error about crti.so not being found:

/usr/bin/ld: skipping incompatible /usr/lib/crti.o when searching for /usr/lib/crti.o
/usr/bin/ld: cannot find /usr/lib/crti.o
build.lpr(16,1) Error: Error while linking

As the Wiki is extremely vague as to what to do for fpc.cfg (Sorry, but "Edit your /etc/fpc.cfg file if needed" is not very useful), I did change this line:

#-Fl/lib;/usr/lib

to

-Fl/lib;/usr/lib;-Fl/lib32;/usr/lib32

However, to no avail. However, I did discover that /usr/lib32 doesn't even have crti.o, so a little more investigation made me realize I needed to install the "libc6-dev-i386" package, after which I did, in fact, have that file.

However, I'm still unable to compile a 32-bit executable that includes "cthreads" in its uses clause. ld still complains about not being able to find crti.o, despite my having added /usr/lib32 to the -Fl line of my fpc.cfg.

I do have this in my fpc.cfg:
==============================
# set binutils prefix

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

#IFNDEF linux
#DEFINE NEEDCROSSBINUTILS
#ENDIF

#IFDEF FPC_CROSSCOMPILING
#IFDEF NEEDCROSSBINUTILS
-XP$fpctarget-
#ENDIF NEEDCROSSBINUTILS
#ENDIF
==============================

but I don't know if that's correct or whatever, that's just what samplecfg generated.

Observe:
compiling for 64-bit
==============================
$ /usr/local/bin/fpc -MObjFPC -Scgi -O1 -gl -vewnhi -l -Fu. -obuild build.lpr Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.3.1 [2009/11/02] for x86_64 Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for x86-64
Compiling build.lpr
Linking build
ld here i am
ld.real: warning: link.res contains output sections; did you forget -T? 17 lines compiled, 0.2 sec
2 hint(s) issued
==============================

attempting to compile for 32-bit
==============================
$ /usr/local/bin/fpc -Pi386 -MObjFPC -Scgi -O1 -gl -vewnhi -l -Fu. -obuild build.lpr
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.3.1 [2009/11/02] for i386 Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for i386
Compiling build.lpr
Linking build
ld: warning: link.res contains output sections; did you forget -T? ld: skipping incompatible /usr/lib/crti.o when searching for /usr/lib/crti.o ld: cannot find /usr/lib/crti.o
build.lpr(16,1) Error: Error while linking
build.lpr(16,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
Error: /usr/local/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
==============================

I sort of think that /usr/bin/i386-linux-ld isn't being called. I added an "echo here I am" sort of line to that bash script, and I never see that echo happen.

I'm sure there's some magic I need to do in my fpc.cfg file, but I'm having a hard time finding specifically what it is. I'd really like to be able to compile for x86_64 and i386 in the same development environment simply by selecting a different target from the Lazarus UI and have it "just work."

If anyone can offer assistance, I'd surely appreciate it.

-SG

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com
Seth Grover
to Seth Grover

Okay, in further investigation I am now manually forcing fpc to use i386-linux-ld for linking by using the "-Pi386 -XPi386-linux-" compiler flags (-P for the target and -XP for the binutils prefix). I assume there's something wrong in my fpc.cfg or it would do this manually, but I don't know what it is. Still, at least I'm getting i386-linux-ld to be called.

However, ld is still not searching /usr/lib32. I also tried manually adding -Fl/usr/lib32 to the fpc command line but that didn't help.

So apparently I have to somehow tell ld to look there...

-SG

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com On Mon, Nov 2, 2009 at 12:45 PM, Seth Grover wrote: > I'm trying to cross-compile on Ubuntu 9.10 x86_64 for i386. Here's > what I've done so far: > > I got FPC from the fixes_2_4 branch in SVN and did make/make install. > > I used samplecfg to generate /etc/fpc/fpc.cfg. > > I followed the wiki > (http://wiki.lazarus.freepascal.org/Cross_compiling#To_Linux) and did > the steps listed there, including creating the i386-linux-ld and > i386-linux-ls scripts in /usr/bin and compiling for the i386 target, > so I ended up with a ppc386. > >  At this point I could do a simple "hello world" program which would > generate a 64-bit binary if i selected x86_64 for the target in > lazarus under "Compiler Options | Code" and a 32-bit binary if i > selected i386 as the target. So far so good. > > I then tried to compile something a bit more complicated (not that > much more, though: I just tried to include "cthreads") and I got an > error about crti.so not being found: > > /usr/bin/ld: skipping incompatible /usr/lib/crti.o when searching for > /usr/lib/crti.o > /usr/bin/ld: cannot find /usr/lib/crti.o > build.lpr(16,1) Error: Error while linking > > As the Wiki is extremely vague as to what to do for fpc.cfg (Sorry, > but "Edit your /etc/fpc.cfg file if needed" is not very useful), I did > change this line: > > #-Fl/lib;/usr/lib > > to > > -Fl/lib;/usr/lib;-Fl/lib32;/usr/lib32 > > However, to no avail. However, I did discover that /usr/lib32 doesn't > even have crti.o, so a little more investigation made me realize I > needed to install the "libc6-dev-i386" package, after which I did, in > fact, have that file. > > However, I'm still unable to compile a 32-bit executable that includes > "cthreads" in its uses clause. ld still complains about not being able > to find crti.o, despite my having added /usr/lib32 to the -Fl line of > my fpc.cfg. > > I do have this in my fpc.cfg: > ============================== > # set binutils prefix > > #IFNDEF CPUI386 > #IFNDEF CPUAMD64 > #DEFINE NEEDCROSSBINUTILS > #ENDIF > #ENDIF > > > #IFNDEF linux > #DEFINE NEEDCROSSBINUTILS > #ENDIF > > > #IFDEF FPC_CROSSCOMPILING > #IFDEF NEEDCROSSBINUTILS >  -XP$fpctarget- > #ENDIF NEEDCROSSBINUTILS > #ENDIF > ============================== > > but I don't know if that's correct or whatever, that's just what > samplecfg generated. > > Observe: > compiling for 64-bit > ============================== > $ /usr/local/bin/fpc  -MObjFPC -Scgi -O1 -gl -vewnhi -l -Fu. -obuild build.lpr > Hint: Start of reading config file /etc/fpc.cfg > Hint: End of reading config file /etc/fpc.cfg > Free Pascal Compiler version 2.3.1 [2009/11/02] for x86_64 > Copyright (c) 1993-2009 by Florian Klaempfl > Target OS: Linux for x86-64 > Compiling build.lpr > Linking build > ld here i am > ld.real: warning: link.res contains output sections; did you forget -T? > 17 lines compiled, 0.2 sec > 2 hint(s) issued > ============================== > > attempting to compile for 32-bit > ============================== > $ /usr/local/bin/fpc -Pi386 -MObjFPC -Scgi -O1 -gl -vewnhi -l -Fu. > -obuild build.lpr > Hint: Start of reading config file /etc/fpc.cfg > Hint: End of reading config file /etc/fpc.cfg > Free Pascal Compiler version 2.3.1 [2009/11/02] for i386 > Copyright (c) 1993-2009 by Florian Klaempfl > Target OS: Linux for i386 > Compiling build.lpr > Linking build > ld: warning: link.res contains output sections; did you forget -T? > ld: skipping incompatible /usr/lib/crti.o when searching for /usr/lib/crti.o > ld: cannot find /usr/lib/crti.o > build.lpr(16,1) Error: Error while linking > build.lpr(16,1) Fatal: There were 1 errors compiling module, stopping > Fatal: Compilation aborted > Error: /usr/local/bin/ppc386 returned an error exitcode (normal if you > did not specify a source file to be compiled) > ============================== > > I sort of think that /usr/bin/i386-linux-ld isn't being called. I > added an "echo here I am" sort of line to that bash script, and I > never see that echo happen. > > I'm sure there's some magic I need to do in my fpc.cfg file, but I'm > having a hard time finding specifically what it is. I'd really like to > be able to compile for x86_64 and i386 in the same development > environment simply by selecting a different target from the Lazarus UI > and have it "just work." > > If anyone can offer assistance, I'd surely appreciate it. > > -SG > > -- > This email is fiction. Any resemblance to actual events > or persons living or dead is purely coincidental. > > Seth Grover > sethdgrover[at]gmail[dot]com >
Marco van de Voort
to Seth Grover

In our previous episode, Seth Grover said:

Show quoted text 11 lines
Okay, in further investigation I am now manually forcing fpc to use i386-linux-ld for linking by using the "-Pi386 -XPi386-linux-" compiler flags (-P for the target and -XP for the binutils prefix). I assume there's something wrong in my fpc.cfg or it would do this manually, but I don't know what it is. Still, at least I'm getting i386-linux-ld to be called. However, ld is still not searching /usr/lib32. I also tried manually adding -Fl/usr/lib32 to the fpc command line but that didn't help. So apparently I have to somehow tell ld to look there...

You might have to tell it simply NOT to look in /usr/lib

E.g. like described in paragraph 3.4.1 of the buildfaq:

http://www.stack.nl/~marcov/buildfaq.pdf

Seth Grover
Show quoted text 6 lines
You might have to tell it simply NOT to look in /usr/lib E.g. like described in paragraph 3.4.1 of the buildfaq: http://www.stack.nl/~marcov/buildfaq.pdf

Thank you! That seemed to get me past the rest of my errors.

The final working command was:

/usr/local/bin/fpc -Xd -Pi386 -XPi386-linux- -MObjFPC -Scgi -XX -vewnhi -l -Fu. -oproject1 project1.lpr

The one other thing I had to do was change one of the lines in fpc.cfg so that it would look in "/usr/lib/gcc/x86_64-linux-gnu/32/4.4.1" rather than "/usr/lib/gcc/x86_64-linux-gnu/4.4.1".

So basically I ended up with:

==========================================
#ifdef cpui386
-Fl/usr/lib/gcc/x86_64-linux-gnu/32/4.4.1
-Fl/lib32
-Fl/usr/lib32
#endif
==========================================

I haven't tried to build anything too complicated, but most simple compilations seem to be working.

Thanks again!

-SG

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com