1
/usr/bin/ld: i386:x86-64 architecture of input file `build/gengenrtl.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `build/errors.o' is incompatible with i386 output
/usr/bin/ld: build/gengenrtl.o: file class ELFCLASS64 incompatible with ELFCLASS32
/usr/bin/ld: final link failed: File in wrong format
collect2: error: ld returned 1 exit status

I don't get if the problem is ld or the given library.

my configuration is

 CC="gcc -m32" \
 CFLAGS="-m32" \
 LD="<path>/bin/32/binutils/2.23.2/bin/ld" \
 LDFLAGS="-m32" \
 ./configure \
 --build=i586-pc-linux-gnu \
 --host=i586-pc-linux-gnu \
 --target=i586-pc-linux-gnu \
 --enable-shared \
 --enable-static \
 --enable-languages=c,c++ \
 --enable-bootstrap \
 --prefix=<path>/bin/32/gcc/i586 \
 --disable-stage1-checking \ 
 --with-gmp=<path>/lib/32/gmp/5.1.2 \
 --with-mpfr=<path>/lib/32/mpfr/3.1.2 \
 --with-mpc=<path>/lib/32/mpc/1.0.1 \
 --with-cloog=<path>/lib/32/cloog/0.18.0 \
 --without-ppl

Apparently I can't change the ld executable so easily, gcc keeps compiling with the global system /usr/bin/ld.

Someone can say what is going on here and how to fix this linking phase ?

I'm under Ubuntu 64 bit and I'm trying to compile a 32 bit build of gcc, of course I have already compiler gmp, mpc, mpfr for 32 bits.

user2485710
  • 8,623
  • 9
  • 48
  • 92

2 Answers2

4

Of course you can build gcc from source as 32-bit, using a 64-bit OS, compiler and linker. The problem is definitely not "ld".

You're doing exactly the right thing: specifying "-m32" in CFLAGS and LDFLAGS.

The problem is that build/gengenrtl.o and build/errors.o appear to have been built for 64-bit (instead of 32-bit).

SUGGESTIONS:

1) Check the makefile, and check your build log. See if there's anything "different" about the build commands for those two files.

2) Use the "nm" command to verify that the rest of your *.o object files were correctly built as 32-bit - that only "gengenrtl.o" and "errors.o" were (incorrectly) built as ELFCLASS64.

'Hope that helps...

paulsm4
  • 99,714
  • 15
  • 125
  • 160
  • 1
    and if they are, indeed, 64 bit ? How I can build that libraries with a 32 bit elf ? ... I don't get the logic behind this, if this libraries are so important why not just put a flag or more options ? I cant even see a flag related to those files – user2485710 Aug 15 '13 at 22:55
  • also what is the name/location of the log ? – user2485710 Aug 15 '13 at 22:56
0

I have solved similar problem (Compile gcc on amd64, for running on i686, and target is mips) with adding following to make command line:

CC="gcc -m32" CXX="g++ -m32" LDFLAGS=-m32

No need to specify full path to ld. But you forgot specify which C++ compiler to use.

fk0
  • 345
  • 1
  • 9