0
votes

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
...
1
Looks like I forgot second flag: CXXFLAG=-m32. So, I need both: CFLAGS=-m32 and CXXFLAGS=-m32. But now I stuck with following error: checking for suffix of object files... configure: error: in .../gcc-4.9.4/build/mips/libgcc': configure: error: cannot compute suffix of object files: cannot compile See `config.log' for more details.fk0
FAQ points (gcc.gnu.org/wiki/…) that config.log might contain errors, but I can't found no one (except of gcc -V -- wrong option).fk0
found, that I have libisl-0.18 (no version 0.15 in current debian for i386), but gcc requires 0.15. After invocation of download_prerequisites stript (in gcc directory) process started... but again: configure: error: cannot compute suffix of object files: cannot compile in libgcc. Have no ideas, that should I find in config.log.fk0
I'm curious why you want to make i386 binaries that target MIPS. Why not normal x86-64 binaries that target MIPS? Do you have some crusty old 32-bit x86 machine you want to use for MIPS cross-development, but you don't want to use a C compiler on that host?Peter Cordes
Yes, I want to compile redistributable package for 32-bit machines. Only ways is to use virtual machine, or pbuilder?fk0

1 Answers

1
votes

I found solution, need to pass following environment variables in make command line:

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

Thats all. Exporting of CFLAGS will not work. You need to export CFLAGS, CXXFLAGS and LDFLAGS, but few pitfalls exists here:

  1. CFLAGS=-m32 also will be exported to MIPS compiler, which have no knowledge about -m32 flag (failure when building libgcc);
  2. CXXFLAGS=-m32 have influence on libraries used by gcc and configure script fails;
  3. You can use ALL_CFLAGS instead, but it doesn't works for gcc itself and libcpp.

See also similar question: Building 32 bit GCC from source on 64 bit: linking issue