我正在尝试在 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
答案2
为了gcc
在 Alpine Linux 上进行编译,需要执行以下步骤:
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
我们构建了libgcc
一个低级支持库,编译器期望在编译时可用。链接libgcc
提供整数、浮点、小数、堆栈展开(对于异常处理有用)和其他支持功能。请注意,我们并不是简单地运行make && make install
,因为这会构建太多的组件,并非所有组件都gcc
准备好针对您未完成的操作系统。