Mac安装GCC
本教程是因为 Mac 自带的是 clang 编译器,但是想要学习一下 gcc 的后端模块,所以打算自己装一下。
步骤一:前置库
brew install gmp mpfr libmpc isl zstd
步骤二:获取镜像库
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
tar -zxvf gcc-13.2.0.tar.gz
步骤三:构建 GCC
因为 GCC 的构建需要一些其他库的支持,所以可以先用 brew 命令找到依赖库:
brew --prefix gmp
brew --prefix mpfr
brew --prefix libmpc
# 结果为
/opt/homebrew/opt/gmp
/opt/homebrew/opt/mpfr
/opt/homebrew/opt/libmpc
构建命令:
../configure \ ─╯
--enable-languages=c,c++ \
--disable-multilib \
--enable-checking=release \
--with-system-zlib \
--with-gmp=/opt/homebrew/opt/gmp \
--with-mpfr=/opt/homebrew/opt/mpfr \
--with-mpc=/opt/homebrew/opt/libmpc
make -s -j$(sysctl -n hw.logicalcpu)
构建时遇到了一个错误:
> configure: error: *** LIBRARY_PATH shouldn't contain the current directory when *** building gcc. Please change the environment variable *** and run configure again. make[2]: *** [configure-stage1-gcc] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [stage1-bubble] Error 2 make: *** [all] Error 2
查证方案:❯ echo $LIBRARY_PATH 打印:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
需要修改为:export LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
然后重新 configure 那一步开始……
但是无法解决:
*** Configuration aarch64-apple-darwin24.1.0 not supported
make[2]: *** [configure-stage1-gcc] Error 1
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2
评论