macOS 10.13.6下Homebrew安装SDL2库及C++编译器失败
在macOS 10.13.6(High Sierra)上解决Homebrew编译依赖失败问题
问题概述
在macOS 10.13.6系统中,使用Homebrew安装SDL2_ttf、SDL2_image时均出现C++编译相关错误,尝试安装gcc/llvm也无法成功,核心问题为旧系统与新版Homebrew、依赖包的兼容性冲突。
解决步骤
1. 安装兼容的Xcode Command Line Tools
macOS 10.13.6最高支持Xcode 10.1,确保已安装对应版本的Command Line Tools:
- 检查当前版本:
xcode-select --version - 若版本不符,下载安装Xcode 10.1后,执行:
xcode-select --install - 手动指定Xcode路径(若需):
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
2. 降级Homebrew至支持High Sierra的版本
新版Homebrew已停止支持High Sierra,需切换到兼容分支:
cd /usr/local/Homebrew git stash git checkout 2.7.0 brew update
3. 安装兼容版本的编译器与依赖包
安装gcc@9(最后支持High Sierra的gcc版本)
brew install gcc@9
配置环境变量:
echo 'export PATH="/usr/local/opt/gcc@9/bin:$PATH"' >> ~/.bash_profile echo 'export LDFLAGS="-L/usr/local/opt/gcc@9/lib"' >> ~/.bash_profile echo 'export CPPFLAGS="-I/usr/local/opt/gcc@9/include"' >> ~/.bash_profile source ~/.bash_profile
安装兼容版本的SDL2_ttf和SDL2_image
直接安装旧版本包:
brew install sdl2_ttf@2.0.15 brew install sdl2_image@2.0.5
若上述命令失效,使用历史Formula文件安装:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8b9d6d6b7e0a210b42b98f88d4f3f0a7d32f1e48/Formula/sdl2_ttf.rb brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8b9d6d6b7e0a210b42b98f88d4f3f0a7d32f1e48/Formula/sdl2_image.rb
4. 手动指定编译器
若仍有编译错误,强制使用gcc@9作为编译器:
export CXX=g++-9 export CC=gcc-9 brew install sdl2_ttf sdl2_image
内容的提问来源于stack exchange,提问作者Dong Le
相关产品推荐
相关产品推荐

