Recent

Author Topic: Linker problem with cross-compile from amd64 to i386: Cannot find crti.o  (Read 6740 times)

greyspammer

  • New member
  • *
  • Posts: 6
Greetings!

I am working on Kubuntu 13.10 (amd64) and currently trying to build a 32bit version of my fiddling with Lazarus. Here's what I have done so far:
Since Ubuntu does not allow parallel installation of fp-compiler-2.6.2 and fp-compiler-2.6.2:i386 (for whatever reason), I manually compiled an i386 version of fpc and installed it in /opt/fpc-i386. That seemed to work. At least I got no errors and I can call that ppc386 binary just fine.

Then I added these lines to my /etc/fpc.cfg:

Code: [Select]
#IFDEF CPUI386
-Fu/opt/fpc-i386/lib/fpc/2.6.2/units/i386-linux/
-Fu/opt/fpc-i386/lib/fpc/2.6.2/units/i386-linux/*
-Fu/opt/fpc-i386/lib/fpc/2.6.2/units/i386-linux/rtl

-Fl/opt/fpc-i386/lib/
-Fl/usr/libx32/

-FD/opt/fpc-i386/bin/
#ENDIF

I hope that's correct, I couldn't find any explicit instructions on that. http://wiki.lazarus.freepascal.org/Cross_compiling just says you may have to edit the file but doesn't say in what way.

Now, when I try to build my project, I get this error message:

Code: [Select]
$ LC_ALL=C ~/lazarus/lazbuild --widgetset=qt --cpu=i386 --compiler=/opt/fpc-i386/lib/fpc/2.6.2/ppc386 foohelper.lpr
primary config path: /home/greyspammer/.lazarus
TCompiler.Compile WorkingDir="/home/greyspammer/devel/foo-helper/" CompilerFilename="/opt/fpc-i386/lib/fpc/2.6.2/ppc386" CompilerParams=" -MObjFPC -Scghi -O1 -Pi386 -g -gl -vewnhi -Filib/i386-linux -Fu../../lazarus/components/thtmlport/package/units/i386-linux -Fu../../lazarus/components/rxnew/lib/i386-linux -Fu../../lazarus/components/rx/lib/i386-linux -Fu../../lazarus/ideintf/units/i386-linux/qt -Fu../../lazarus/lcl/units/i386-linux/qt -Fu../../lazarus/lcl/units/i386-linux -Fu../../lazarus/components/lazutils/lib/i386-linux -Fu../../lazarus/packager/units/i386-linux -Fu. -FUlib/i386-linux/ -l -dLCL -dLCLqt foohelper.lpr"
[TCompiler.Compile] CmdLine="/opt/fpc-i386/lib/fpc/2.6.2/ppc386  -MObjFPC -Scghi -O1 -Pi386 -g -gl -vewnhi -Filib/i386-linux -Fu../../lazarus/components/thtmlport/package/units/i386-linux -Fu../../lazarus/components/rxnew/lib/i386-linux -Fu../../lazarus/components/rx/lib/i386-linux -Fu../../lazarus/ideintf/units/i386-linux/qt -Fu../../lazarus/lcl/units/i386-linux/qt -Fu../../lazarus/lcl/units/i386-linux -Fu../../lazarus/components/lazutils/lib/i386-linux -Fu../../lazarus/packager/units/i386-linux -Fu. -FUlib/i386-linux/ -l -dLCL -dLCLqt foohelper.lpr"
Hint: Start of reading config file /etc/fpc.cfg
Hint: End of reading config file /etc/fpc.cfg
Free Pascal Compiler version 2.6.2 [2013/11/02] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling foohelper.lpr
foohelper.lpr(10,30) Hint: Unit "foodownloader" not used in foohelper
foohelper.lpr(10,52) Hint: Unit "downloadthread" not used in foohelper
foohelper.lpr(10,68) Hint: Unit "fooinstaller" not used in foohelper
Compiling resource lib/i386-linux/foohelper.or
Linking foohelper
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/crti.o when searching for /usr/lib/x86_64-linux-gnu/crti.o
/usr/bin/ld: cannot find /usr/lib/x86_64-linux-gnu/crti.o
foohelper.lpr(20,1) Error: Error while linking
foohelper.lpr(20,1) Fatal: There were 1 errors compiling module, stopping
ERROR: failed compiling of project /home/greyspammer/devel/foo-helper/foohelper.lpi

And, well, the compiler is both right and wrong. I understand that the x64 version of crti.o isn't of much use to it but there is a perfectly fine i386 version in /usr/libx32:

Code: [Select]
$ dpkg -S crti.o
libc6-dbg:amd64: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crti.o
libc6-dev-i386: /usr/lib32/crti.o
libc6-dbg:i386: /usr/lib/debug/usr/lib/i386-linux-gnu/crti.o
libc6-dev:amd64: /usr/lib/x86_64-linux-gnu/crti.o
libc6-dev-x32: /usr/libx32/crti.o

It just does not use it. Despite the fact that I wrote the path in the fpc.cfg. Even if I call the compiler manually (copy & paste of the CmdLine above) and add "-Fl/usr/libx32", it still print the same error.

I assume I am doing something wrong but I cannot figure out what it is.
« Last Edit: November 02, 2013, 01:20:21 pm by greyspammer »

edvard

  • Full Member
  • ***
  • Posts: 165
Re: Linker problem with cross-compile from amd64 to i386: Cannot find crti.o
« Reply #1 on: January 11, 2015, 08:56:19 pm »
I have been tearing my hair out for a month or so trying to get at least FPC compiling 32-bit from a 64-bit system.  I followed the instructions in the wiki, rpdev's page, Marco's Build FAQ, and this thread, but in the end, I had the same problem as stated here and found this question in my search for solutions.  I finally killed this one and thought this was an appropriate place to post.

At the bottom of your /etc/fpc.cfg, there is a line that reads:
Code: [Select]
# multiarch library search path
-Fl/usr/lib/$fpctarget-*

Well, in Debian, for some stupid reason, libc6-i386 libraries get installed in /usr/lib32 instead of /usr/lib/i386-linux-gnu.  SO...

Edit your fpc.cfg, and put this line right after the one mentioned above:
Code: [Select]
-Fl/usr/lib32
Save it, and try to compile a "hello world" program:
Code: [Select]
ppc386 hello.pas
Free Pascal Compiler version 2.6.4 [2015/01/11] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling hello.pas
Linking hello


/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
8 lines compiled, 0.3 sec

Yay!  ...and 'file' reports:
Code: [Select]
file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped

Done.  SO done.

I had to install libx11-dev and libqt4pas-dev packages for i386 and that got me compiling for Qt4 with Lazarus.   Debian wouldn't let me install i386 AND x86_64 packages for some things that GTK depends on, so that's a no-go.  I'm less and less ok with GTK lately anyway.
All children left unattended will be given a mocha and a puppy.

Debian 'Testing' 64-bit | Xfce 4.12 | FreePascal 3.0 + Lazarus 1.6.2, GTK2+ and Qt

Leledumbo

  • Hero Member
  • *****
  • Posts: 8114
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Linker problem with cross-compile from amd64 to i386: Cannot find crti.o
« Reply #2 on: January 12, 2015, 06:51:58 am »
Same problem here, been about 2-3 months unable to cross compile to i386 (prior, it was fine). Following edvard advice, I'm getting an improvement but not yet done. The linker script now contains:
Code: [Select]
SEARCH_DIR("/lib/") <- symlink to /usr/lib
SEARCH_DIR("/usr/lib/")
SEARCH_DIR("/usr/lib32/")
SEARCH_DIR("/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/32/")
No idea why it puts 64-bit library path as well. Going down:
Code: [Select]
INPUT(
/lib/crti.o <- this is 64-bit one and is certainly WRONG
Going down again:
Code: [Select]
)
INPUT(
-lpthread
-ldl
-lQt4Pas
-lX11
-lasound
)
GROUP(
-lc
)
INPUT(
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/32/crtend.o
/lib/crtn.o <- WRONG too
)
Changing all those WRONGs to /usr/lib32 and it links successfully. Something seems wrong in the linker script generator.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7641
Re: Linker problem with cross-compile from amd64 to i386: Cannot find crti.o
« Reply #3 on: January 12, 2015, 09:41:15 am »
Try passing -Xd. It skips the built-in paths in some scenarios. It might get rid of the /usr/lib.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8114
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Linker problem with cross-compile from amd64 to i386: Cannot find crti.o
« Reply #4 on: January 12, 2015, 09:54:22 am »
Try passing -Xd. It skips the built-in paths in some scenarios. It might get rid of the /usr/lib.
Damn it works :o
I never need to use this option previously except for targetting androiid. It seems mandatory now for all except win32/win64 cross compilation scenario, eh?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7641
Re: Linker problem with cross-compile from amd64 to i386: Cannot find crti.o
« Reply #5 on: January 12, 2015, 11:34:20 am »
Damn it works :o
I never need to use this option previously except for targetting androiid. It seems mandatory now for all except win32/win64 cross compilation scenario, eh?

Windows doesn't have libc, libgcc etc by default. One can link to system dlls without such directories etc present.
If you start to use gcc related things, like mingw libc stuff, you probably have to pass those paths extra.

Note that the need on this on Linux is sometimes a bit in-transparent, since in the past the rules what the default path is (lib64/lib/lib32) have been changed.