Recently I tried building my own cross compiler inside a docker container. Building the kernel headers, binutils and gcc worked without any issue.
Just by building glibc I came across following error
configure: error: in `/glibc-build':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by GNU C Library configure (see version.h), which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ../glibc-2.27/configure --prefix=/usr --host= --build= --disable-profile --enable-add-ons --with-tls --enable-kernel=2.6.32 --with-__thread --with-binutils=/cross-tools/bin --with-headers=/usr/include --cache-file=config.cache
## --------- ##
## Platform. ##
## --------- ##
hostname = bc17d4761adf
uname -m = x86_64
uname -r = 4.9.184-linuxkit
uname -s = Linux
uname -v = #1 SMP Tue Jul 2 22:58:16 UTC 2019
/usr/bin/uname -p = unknown
/bin/uname -X = unknown
/bin/arch = unknown
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo = unknown
/bin/machine = unknown
/usr/bin/oslevel = unknown
/bin/universe = unknown
PATH: /usr/local/sbin
PATH: /usr/local/bin
PATH: /usr/sbin
PATH: /usr/bin
PATH: /sbin
PATH: /bin
## ----------- ##
## Core tests. ##
## ----------- ##
configure:2012: loading cache config.cache
configure:2206: checking build system type
configure:2220: result: x86_64-pc-linux-gnu
configure:2240: checking host system type
configure:2253: result: x86_64-pc-linux-gnu
configure:2322: checking for gcc
configure:2349: result: -gcc-7.3.0
configure:2578: checking for C compiler version
configure:2587: -gcc-7.3.0 --version >&5
../glibc-2.27/configure: line 2589: -gcc-7.3.0: command not found
configure:2598: $? = 127
configure:2587: -gcc-7.3.0 -v >&5
../glibc-2.27/configure: line 2589: -gcc-7.3.0: command not found
configure:2598: $? = 127
configure:2587: -gcc-7.3.0 -V >&5
../glibc-2.27/configure: line 2589: -gcc-7.3.0: command not found
configure:2598: $? = 127
configure:2587: -gcc-7.3.0 -qversion >&5
../glibc-2.27/configure: line 2589: -gcc-7.3.0: command not found
configure:2598: $? = 127
configure:2603: checking for suffix of object files
configure:2625: -gcc-7.3.0 -c -O2 conftest.c >&5
../glibc-2.27/configure: line 2627: -gcc-7.3.0: command not found
configure:2629: $? = 127
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU C Library"
| #define PACKAGE_TARNAME "glibc"
| #define PACKAGE_VERSION "(see version.h)"
| #define PACKAGE_STRING "GNU C Library (see version.h)"
| #define PACKAGE_BUGREPORT "https://sourceware.org/bugzilla/"
| #define PACKAGE_URL "http://www.gnu.org/software/glibc/"
| #define PKGVERSION "(GNU libc) "
| #define REPORT_BUGS_TO "<http://www.gnu.org/software/libc/bugs.html>"
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:2643: error: in `/glibc-build':
configure:2645: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
## ---------------- ##
## Cache variables. ##
## ---------------- ##
ac_cv_build=x86_64-pc-linux-gnu
ac_cv_env_CCC_set=
ac_cv_env_CCC_value=
ac_cv_env_CC_set=set
ac_cv_env_CC_value=-gcc-7.3.0
ac_cv_env_CFLAGS_set=set
ac_cv_env_CFLAGS_value=-O2
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_CPP_set=
ac_cv_env_CPP_value=
ac_cv_env_CXXFLAGS_set=
ac_cv_env_CXXFLAGS_value=
ac_cv_env_CXX_set=
ac_cv_env_CXX_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_build_alias_set=set
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=set
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_host=x86_64-pc-linux-gnu
ac_cv_prog_ac_ct_CC=-gcc-7.3.0
libc_cv_c_cleanup=yes
libc_cv_forced_unwind=yes
libc_cv_ssp=no
libc_cv_ssp_strong=no
## ----------------- ##
## Output variables. ##
## ----------------- ##
AR='-ar'
AS=''
ASFLAGS_config=''
AUTOCONF=''
AWK=''
BASH_SHELL=''
BISON=''
BUILD_CC='gcc'
CC='-gcc-7.3.0'
CFLAGS='-O2'
CPP=''
CPPFLAGS=''
CPPUNDEFS=''
CXX=''
CXXFLAGS=''
CXX_BITS_STD_ABS_H=''
CXX_CMATH_HEADER=''
CXX_CSTDLIB_HEADER=''
CXX_SYSINCLUDES=''
DEFINES=''
DEFS=''
ECHO_C=''
ECHO_N='-n'
ECHO_T=''
GPROF=''
INSTALL_DATA=''
INSTALL_INFO=''
INSTALL_PROGRAM=''
INSTALL_SCRIPT=''
LD=''
LDFLAGS=''
LIBGD=''
LIBOBJS=''
LIBS=''
LN_S=''
LTLIBOBJS=''
MAKE=''
MAKEINFO=''
MSGFMT=''
NM=''
OBJCOPY=''
OBJDUMP=''
OBJEXT=''
PACKAGE_BUGREPORT='https://sourceware.org/bugzilla/'
PACKAGE_NAME='GNU C Library'
PACKAGE_STRING='GNU C Library (see version.h)'
PACKAGE_TARNAME='glibc'
PACKAGE_URL='http://www.gnu.org/software/glibc/'
PACKAGE_VERSION='(see version.h)'
PATH_SEPARATOR=':'
PERL=''
PKGVERSION='(GNU libc) '
PKGVERSION_TEXI='(GNU libc) '
PYTHON=''
PYTHON_PROG=''
READELF=''
RELEASE=''
REPORT_BUGS_TEXI='@uref{http://www.gnu.org/software/libc/bugs.html}'
REPORT_BUGS_TO='<http://www.gnu.org/software/libc/bugs.html>'
SED=''
SHELL='/bin/sh'
SYSINCLUDES=''
VERSION=''
ac_ct_CC='-gcc-7.3.0'
ac_ct_CXX=''
all_warnings=''
base_machine=''
bindir='${exec_prefix}/bin'
bindnow=''
build='x86_64-pc-linux-gnu'
build_alias=''
build_cpu='x86_64'
build_nscd=''
build_obsolete_nsl=''
build_os='linux-gnu'
build_pt_chown=''
build_vendor='pc'
cross_compiling='no'
datadir='${datarootdir}'
datarootdir='${prefix}/share'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
dvidir='${docdir}'
enable_timezone_tools=''
enable_werror=''
exec_prefix='NONE'
experimental_malloc=''
fno_unit_at_a_time=''
force_install=''
hardcoded_path_in_tests=''
have_libaudit=''
have_libcap=''
have_selinux=''
have_tunables=''
host='x86_64-pc-linux-gnu'
host_alias=''
host_cpu='x86_64'
host_os='linux-gnu'
host_vendor='pc'
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
ldd_rewrite_script=''
libc_cv_cc_loop_to_function=''
libc_cv_cc_nofma=''
libc_cv_cc_pie_default=''
libc_cv_cc_submachine=''
libc_cv_cc_with_libunwind=''
libc_cv_complocaledir=''
libc_cv_cxx_thread_local=''
libc_cv_fpie=''
libc_cv_gcc_unwind_find_fde=''
libc_cv_has_glob_dat=''
libc_cv_hashstyle=''
libc_cv_insert=''
libc_cv_localstatedir=''
libc_cv_mtls_dialect_gnu2=''
libc_cv_multidir=''
libc_cv_nss_crypt=''
libc_cv_output_format=''
libc_cv_pic_default=''
libc_cv_pie_default=''
libc_cv_protected_data=''
libc_cv_rootsbindir=''
libc_cv_rtlddir=''
libc_cv_slibdir=''
libc_cv_ssp='no'
libc_cv_static_nss_crypt=''
libc_cv_sysconfdir=''
libc_cv_with_fp=''
libc_cv_z_combreloc=''
libc_cv_z_execstack=''
libc_extra_cflags=''
libc_extra_cppflags=''
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
link_obsolete_rpc=''
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mach_interface_list=''
mandir='${datarootdir}/man'
multi_arch=''
no_stack_protector=''
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='/usr'
profile=''
program_transform_name='s,x,x,'
psdir='${docdir}'
sbindir='${exec_prefix}/sbin'
shared=''
sharedstatedir='${prefix}/com'
stack_protector=''
static=''
static_nss=''
subdirs=''
submachine=''
sysconfdir='${prefix}/etc'
sysheaders=''
sysnames=''
target_alias=''
use_default_link=''
use_ldconfig=''
use_nscd=''
## ----------- ##
## confdefs.h. ##
## ----------- ##
/* confdefs.h */
#define PACKAGE_NAME "GNU C Library"
#define PACKAGE_TARNAME "glibc"
#define PACKAGE_VERSION "(see version.h)"
#define PACKAGE_STRING "GNU C Library (see version.h)"
#define PACKAGE_BUGREPORT "https://sourceware.org/bugzilla/"
#define PACKAGE_URL "http://www.gnu.org/software/glibc/"
#define PKGVERSION "(GNU libc) "
#define REPORT_BUGS_TO "<http://www.gnu.org/software/libc/bugs.html>"
configure: exit 1
Dockerfile
FROM ubuntu:18.04
#set main directory
ARG HOSTOS="/host-os"
COPY packages /usr/
RUN apt-get update -y
RUN apt-get upgrade -y
#install packages
RUN apt-get install gcc wget curl build-essential libncurses-dev perl grub2-common rsync bison gawk m4 python3 texinfo -y
#point /bin/sh to bash
RUN ln -sf bash /bin/sh
#turn off bash hash functions
RUN set +h
#make files only writeable by owner
RUN umask 022
#create main directory
RUN mkdir -pv ${HOSTOS}
#setting needed variables
ARG LC_ALL=POSIX
ARG PATH=${HOSTOS}/cross-tools/bin:/bin:/usr/bin
#create filesystem hierarchy TODO FIRST
RUN mkdir -pv ${HOSTOS}/{bin,boot/{grub},dev,etc,opt,home,lib/{firmware,modules},lib64,mnt}
RUN mkdir -pv ${HOSTOS}/{proc,media/{floppy,cdrom},sbin,srv,sys}
RUN mkdir -pv ${HOSTOS}/var/{lock,log,mail,run,spool}
RUN mkdir -pv ${HOSTOS}/var/{opt,cache,lib/{misc,locate},local}
RUN install -dv -m 0750 ${HOSTOS}/root
RUN install -dv -m 1777 ${HOSTOS}{/var,}/tmp
RUN install -dv ${HOSTOS}/etc/init.d
RUN mkdir -pv ${HOSTOS}/usr/{,local/}{bin,include,lib{,64},sbin,src}
RUN mkdir -pv ${HOSTOS}/usr/{,local/}share/{doc,info,locale,man}
RUN mkdir -pv ${HOSTOS}/usr/{,local/}share/{misc,terminfo,zoneinfo}
RUN mkdir -pv ${HOSTOS}/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
RUN for dir in ${HOSTOS}/usr{,/local}; do ln -sv share/{man,doc,info} ${dir}; done
RUN install -dv ${HOSTOS}/cross-tools{,/bin}
RUN ln -svf ../proc/mounts ${HOSTOS}/etc/mtab
RUN echo 'root::0:0:root:/root:/bin/ash'\ >> ${HOSTOS}/etc/passwd
COPY files/group ${HOSTOS}/etc/group
COPY files/fstap ${HOSTOS}/etc/fstap
COPY files/profile ${HOSTOS}/etc/profile
RUN echo "horst"> ${LJOS}/etc/HOSTNAME
COPY files/issue ${HOSTOS}/etc/issue
COPY files/inittab ${HOSTOS}/etc/inittab
COPY files/mdev.conf ${HOSTOS}/etc/mdev.conf
RUN touch ${HOSTOS}/var/run/utmp ${HOSTOS}/var/log/{btmp,lastlog,wtmp}
RUN chmod -v 664 ${HOSTOS}/var/run/utmp ${HOSTOS}/var/log/lastlog
RUN unset CFLAGS
RUN unset CXXFLAGS
ARG HOSTOS_HOST="x86_64-cross-linux-gnu"
ARG HOSTOS_TARGET="x86_64-unknown-linux-gnu"
ARG HOSTOS_CPU="k8"
ARG HOSTOS_ARCH="x86_64"
ARG HOSTOS_ENDIAN="little"
#copy packages
COPY packages/* /
#build kernel headers
RUN tar xf /linux-5.4.10.tar.xz -C /
RUN make -C /linux-5.4.10 mrproper
RUN make ARCH=${HOSTOS_ARCH} -C /linux-5.4.10 headers_check
RUN make ARCH=${HOSTOS_ARCH} -C /linux-5.4.10 INSTALL_HDR_PATH=dest headers_install
RUN cp -rv /linux-5.4.10/dest/include/* ${HOSTOS}/usr/include
#build binutils
RUN tar xf /binutils-2.30.tar.xz -C /
RUN mkdir /binutils-build
RUN cd /binutils-build/ && ../binutils-2.30/configure --prefix=${HOSTOS}/cross-tools --target=${HOSTOS_TARGET} --with-sysroot=${HOSTOS} --disable-nls --enable-shared --disable-multilib
RUN make configure-host -C /binutils-build/
RUN make -C /binutils-build/
RUN ln -sv lib ${HOSTOS}/cross-tools/lib64
RUN make install -C /binutils-build/
RUN cd /binutils-build/ && cp -v ../binutils-2.30/include/libiberty.h ${HOSTOS}/usr/include
#build gcc
RUN tar xf /gcc-7.3.0.tar.xz -C /
RUN tar xjf /gmp-6.1.2.tar.bz2 -C /
RUN mv /gmp-6.1.2 /gcc-7.3.0/gmp
RUN tar xJf /mpfr-4.0.1.tar.xz -C /
RUN mv /mpfr-4.0.1 /gcc-7.3.0/mpfr
RUN tar xzf /mpc-1.1.0.tar.gz -C /
RUN mv /mpc-1.1.0 /gcc-7.3.0/mpc
RUN mkdir /gcc-static
RUN cd /gcc-7.3.0/ && bash /gcc-7.3.0/contrib/download_prerequisites
RUN cd /gcc-static && AR=ar LDFLAGS="-Wl,-rpath,${HOSTOS}/cross-tools/lib" ../gcc-7.3.0/configure --prefix=${HOSTOS}/cross-tools --build=${HOSTOS_HOST} --host=${HOSTOS_HOST} --target=${HOSTOS_TARGET} --with-sysroot=${HOSTOS}/target --disable-nls --disable-shared --with-mpfr-include=$(pwd)/../gcc-7.3.0/mpfr/src --with-mpfr-lib=$(pwd)/mpfr/src/.libs --without-headers --with-newlib --disable-decimal-float --disable-libgomp --disable-libmudflap --disable-libssp --disable-threads --enable-languages=c,c++ --disable-multilib --with-arch=${HOSTOS_CPU}
RUN make all-gcc all-target-libgcc -C /gcc-static
RUN make install-gcc install-target-libgcc -C /gcc-static
RUN cd /gcc-static && ln -vs libgcc.a `${HOSTOS_TARGET}-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
#build glibc
RUN tar xf /glibc-2.27.tar.xz -C /
RUN mkdir /glibc-build
RUN cd /glibc-build && echo "libc_cv_forced_unwind=yes"> config.cache
RUN cd /glibc-build && echo "libc_cv_c_cleanup=yes">> config.cache
RUN cd /glibc-build && echo "libc_cv_ssp=no">> config.cache
RUN cd /glibc-build && echo "libc_cv_ssp_strong=no">> config.cache
#ERROR:
RUN cd /glibc-build && TARGET="${HOSTOS_TARGET}" BUILD_CC="gcc" CC="${HOSTOS_TARGET}-gcc-7.3.0" AR="${HOSTOS_TARGET}-ar" RANLIB="${HOSTOS_TARGET}-ranlib" CFLAGS="-O2" ../glibc-2.27/configure --prefix=/usr --host=${HOSTOS_TARGET} --build=${HOSTOS_HOST} --disable-profile --enable-add-ons --with-tls --enable-kernel=2.6.32 --with-__thread --with-binutils=${HOSTOS}/cross-tools/bin --with-headers=${HOSTOS}/usr/include --cache-file=config.cache
First I tried to resolve this error by installing the dependencies "rsync bison gawk m4 python3 texinfo". Sadly it did not help.
Did I forgot to add some important dependencies?