Alpine Linuxでgccをコンパイルすると、「構成:エラー:Cコンパイルプログラムを実行できません」が発生する

Alpine Linuxでgccをコンパイルすると、「構成:エラー:Cコンパイルプログラムを実行できません」が発生する

Alpine Linuxでgcc-7.3をビルドしようとしています。実行すると、makeこのエラーが発生します。

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

私はgccを次のように設定しました。

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

インストールされたg++の詳細は次のとおりです。

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)

次のパッケージをインストールしました。

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

使用されたmakeコマンドは次のとおりです。

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

config.logでこれを見つけました。

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

--target正しいなどの作業バージョン

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

C コンパイラをテストします。

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

C++ コンパイラをテストします。

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

おすすめ記事