macOS Ventura系统gcc编译器无法运行,请求解决方法
macOS Ventura下gcc编译提示更新include路径的解决方法
重置/重装Xcode Command Line Tools
系统升级后,Command Line Tools的路径可能出现异常,先执行重置命令:xcode-select --reset如果重置无效,重新安装:
xcode-select --install确认gcc的实际来源(区分系统clang与brew版gcc)
macOS系统默认的gcc其实是clang的别名,若你之前用的是Homebrew安装的gcc,先检查当前gcc路径:which gcc如果输出是
/usr/bin/gcc,说明调用的是系统clang,需改用Homebrew安装的gcc(通常命名为gcc-xx,xx是版本号),比如:gcc-13 your_code.c -o output也可以设置别名方便使用,编辑
~/.zshrc或~/.bash_profile,添加:alias gcc='gcc-13'保存后执行
source ~/.zshrc或source ~/.bash_profile生效。重新安装Homebrew版gcc
若Homebrew安装的gcc因系统升级损坏,执行更新并重装:brew update brew reinstall gcc手动指定系统头文件路径编译
编译时直接添加SDK的include路径,先通过以下命令获取SDK路径:xcrun --show-sdk-path假设输出为
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk,编译时使用:gcc -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include your_code.c -o output配置全局include路径环境变量
若不想每次编译都手动加路径,可设置全局环境变量,编辑~/.zshrc或~/.bash_profile,添加:export C_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include export CPLUS_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include保存后执行
source ~/.zshrc或source ~/.bash_profile生效。
内容的提问来源于stack exchange,提问作者Aniruddha Das
相关产品推荐
相关产品推荐

