Building Haiku from source fails in configuration phase

Hello, I’m trying to build Haiku out-of-tree with this command:

$ ../haiku/configure --build-cross-tools x86 ../buildtools

and it’s failing with this command:

$ (cd cross-tools-x86-build/gcc/gcc ; 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 -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -DGENERATOR_FILE -static-libstdc++ -static-libgcc -o build/genmddeps build/genmddeps.o build/read-md.o build/errors.o ../build-i686-pc-linux-gnu/libiberty/libiberty.a) /mnt/vault/mounty/kendall-haiku/cross-tools-x86/i586-pc-haiku/bin/ld: unrecognised emulation mode: elf_i386 Supported emulations: elf_i386_haiku i386pe i386pep collect2: error: ld returned 1 exit status

Obviously the configure script only runs the g++ command; I inserted the cd command to make the failing g++ command run outside the script.

It looks like the configuration script is using my system’s gcc (Gentoo Linux, gcc-5.4.0) with the Haiku buildtools’ ld. What’s the correct solution to that? There’s buildtools/gcc but it’s not clear if this should be used instead of the host system’s own gcc, and if so, how to build it.

Make sure you don’t have “.” in your PATH, it is known to create some problems with building GCC.

Well, the cd command is obviously wrong: when building the cross compiler, you can’t use a cross tool chain. So just drop the cd command, you should get another error message.

Please also have a look at the build log on a buildbot: https://buildbot.haiku-os.org/builders/buildtools-master-geist-bot1-ubuntu64/builds/43/steps/compile%20x86%20buildtools/logs/stdio
It might a little differ with yours because of “-j2”.

As I said, I only inserted the cd command to replicate what the configure script had done before it executed the command that really led to the error message. The last few lines of output from configure are:

g++ -c -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -DGENERATOR_FILE -I. -Ibuild -I/mnt/vault/mounty/buildtools/gcc/gcc -I/mnt/vault/mounty/buildtools/gcc/gcc/build -I/mnt/vault/mounty/buildtools/gcc/gcc/…/include -I/mnt/vault/mounty/buildtools/gcc/gcc/…/libcpp/include
-o build/errors.o /mnt/vault/mounty/buildtools/gcc/gcc/errors.c
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 -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -DGENERATOR_FILE -static-libstdc++ -static-libgcc -o build/genmddeps
build/genmddeps.o build/read-md.o build/errors.o …/build-i686-pc-linux-gnu/libiberty/libiberty.a
/mnt/vault/mounty/kendall-haiku/cross-tools-x86/i586-pc-haiku/bin/ld: unrecognised emulation mode: elf_i386
Supported emulations: elf_i386_haiku i386pe i386pep
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:2619: build/genmddeps] Error 1
make[2]: Leaving directory '/mnt/vault/mounty/kendall-haiku/cross-tools-x86-build/gcc/gcc’
make[1]: *** [Makefile:4121: all-gcc] Error 2
make[1]: Leaving directory '/mnt/vault/mounty/kendall-haiku/cross-tools-x86-build/gcc’
make: *** [Makefile:875: all] Error 2
ERROR: Building gcc failed.

Sorry I saw the cross-tools chain linker and was mislead.
g++ calls /mnt/vault/mounty/kendall-haiku/cross-tools-x86/i586-pc-haiku/bin/ld, which shouldn’t happen, because it’s the cross-tools chain linker. Please first check what Pulkomandy said about the PATH. Using “which ld” in cross-tools-x86-build/gcc/gcc might help.

Relevant excerpt from g++ man page might also help:

-Bprefix
This option specifies where to find the executables, libraries, include files, and data files of the compiler itself.
The compiler driver program runs one or more of the subprograms cpp, cc1, as and ld. It tries prefix
 as a prefix for each program it tries to run, both with and without machine/version/.

For each subprogram to be run, the compiler driver first tries the -B prefix, if any. If that name is
 not found, or if -B was not specified, the driver tries two standard prefixes, which are 
/usr/lib/gcc/ and /usr/local/lib/gcc/. If neither of those results in a file name that is found, the 
unmodified program name is searched for using the directories specified in your PATH environment variable.

OK, thanks for those. Firstly, while digging, I found:

mounty@kendall /mnt/vault/mounty/kendall-haiku $ ls -R cross-tools-x86-build/gcc/gcc/ada/
cross-tools-x86-build/gcc/gcc/ada/:
Makefile gcc-interface

cross-tools-x86-build/gcc/gcc/ada/gcc-interface:
Makefile
The GNU Ada compiler is installed on the host, but surely it would not be of any use or interest to the Haiku build system so why is that directory there?

Anyway, the real wierdness is this:(cd cross-tools-x86-build/gcc/gcc;echo PATH=$PATH;which g++ ld;PATH=/usr/bin:/bin /usr/bin/g++ -O2 -pipe -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -DGENERATOR_FILE -static-libstdc++ -static-libgcc -o build/genmddeps build/genmddeps.o build/read-md.o build/errors.o …/build-i686-pc-linux-gnu/libiberty/libiberty.a)
PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/5.4.0
/usr/bin/g++
/usr/bin/ld
/mnt/vault/mounty/kendall-haiku/cross-tools-x86/i586-pc-haiku/bin/ld: unrecognised emulation mode: elf_i386
Supported emulations: elf_i386_haiku i386pe i386pep
collect2: error: ld returned 1 exit status
Note that setting of PATH in the g++ invocation; it seems that the system’s g++ is picking up the cross-compilation ld, even with a minimal PATH; how does it do that?