I want to compile gcc and binutils for MIPS target. I am working on 64-bit (amd64) machine. And want to obtain binary which is able to run on i686 (not amd64) arhitecture? How should I condigure and build gcc?
If I am adding --host=i686-linux-gnu to ./configure script, then it complains on absence of i686-xxxx tools.
If I am adding CFLAGS=-m32, then I can build binutils, but not gcc, because of following error:
g++ -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -DGENERATOR_FILE -static-libstdc++ -static-libgcc -o build/genconstants \
build/genconstants.o build/read-md.o build/errors.o ../build-x86_64-unknown-linux-gnu/libiberty/libiberty.a
/usr/bin/ld: i386 architecture of input file `../build-x86_64-unknown-linux-gnu/libiberty/libiberty.a(concat.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `../build-x86_64-unknown-linux-gnu/libiberty/libiberty.a(fopen_unlocked.o)' is incompatible with i386:x86-64 output
...
I found solution, need to pass following environment variables in make command line:
Thats all. Exporting of CFLAGS will not work. You need to export CFLAGS, CXXFLAGS and LDFLAGS, but few pitfalls exists here:
See also similar question: Building 32 bit GCC from source on 64 bit: linking issue