2

I am trying to build gcc-7.3 on Alpine Linux. When I run make, I get these errors,

checking whether the C compiler works... configure: error: in `/build/x86_64-pc-linux-gnu/libgomp':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
make[2]: *** [Makefile:20670: configure-stage1-target-libgomp] Error 1
make[2]: Leaving directory '/build'
make[1]: *** [Makefile:22759: stage1-bubble] Error 2
make[1]: Leaving directory '/build'
make: *** [Makefile:23096: bootstrap] Error 2

I have configured gcc as,

/gcc-7.3.0/configure --with-pkgversion="version" --with-bugurl="example.com" --disable-multilib --enable-languages=c --disable-werror

The installed g++ details are,

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-6.4.0/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --with-pkgversion='Alpine 6.4.0' --enable-checking=release --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-default-pie --enable-cloog-backend --enable-languages=c,c++,objc,java,fortran,ada --disable-libssp --disable-libmpx --disable-libmudflap --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-system-zlib --with-linker-hash-style=gnu
Thread model: posix
gcc version 6.4.0 (Alpine 6.4.0)

I have installed the following packages.

g++ musl musl-dev bash gawk gzip make tar gmp mpfr3 mpfr-dev mpc1 mpc1-dev isl isl-dev

The make command used is,

make -j$(nproc --all) BOOT_CFLAGS='-O3' bootstrap

In config.log, I found this,

configure:4876: g++ -V >&5
g++: error: unrecognized command line option '-V'
g++: fatal error: no input files
compilation terminated.
configure:4887: $? = 1
configure:4876: g++ -qversion >&5
g++: error: unrecognized command line option '-qversion'; did you mean '--version'?
g++: fatal error: no input files
compilation terminated.
  • 1
    I'm skeptical that the section of the config.log file you have posted is the relevant one here - there will often be several fatal error messages as autoconf tries different options, you should look for the one that includes the specific error cannot run C compiled programs – steeldriver Mar 22 '18 at 13:03
1

The working version with the correct --target etc

export GCC_VERSION=7.3.0
apk add --no-cache make build-base mpfr-dev mpc1-dev isl-dev
wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
tar -xzf gcc-${GCC_VERSION}.tar.gz
cd gcc-${GCC_VERSION}
./configure \
    --prefix=/usr/local \
    --build=$(uname -m)-alpine-linux-musl \
    --host=$(uname -m)-alpine-linux-musl \
    --target=$(uname -m)-alpine-linux-musl \
    --enable-checking=release \
    --disable-fixed-point \
    --disable-libmpx \
    --disable-libmudflap \
    --disable-libsanitizer \
    --disable-libssp \
    --disable-libstdcxx-pch \
    --disable-multilib \
    --disable-nls \
    --disable-symvers \
    --disable-werror
make -j $(nproc)
make install

Test C compiller:

echo '#include <stdio.h>
int main() {
    printf("Hello, C world!\n");
    return 0;
}' | gcc -x c - && ./a.out

Test C++ compiller:

echo '#include <iostream>
int main () {
  std::cout << "Hello, C++ world!\n";
  return 0;
}' | g++ -x c++ - && ./a.out
0

In order to compile gcc on Alpine linux there is a list of steps below:

apk add --no-cache make build-base mpfr-dev mpc1-dev isl-dev
wget https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
tar -xzvf gcc-7.3.0.tar.gz
mkdir objdir
cd objdir
./../gcc-7.3.0/configure --prefix=$HOME/GCC-7.3.0 --with-pkgversion="version" --with-bugurl="example.com" --disable-multilib --enable-languages=c --disable-werror
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

We build libgcc, a low-level support library that the compiler expects available at compile time. Linking against libgcc provides integer, floating point, decimal, stack unwinding (useful for exception handling) and other support functions. Note how we are not simply running make && make install as that would build way too much, not all components of gcc are ready to target your unfinished operating system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.