xcode 如何在mac终端中使用gcc编译器而不是clang

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18976922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:53:54  来源:igfitidea点击:

How to use the gcc compiler in the mac terminal instead of clang

xcodemacosgccclang

提问by user1698555

Is there a way to change the compiler to gcc from clang? I have the command line tools installed and am trying to use the terminal to compile instead of xcode itself.

有没有办法将编译器从 clang 更改为 gcc?我安装了命令行工具,并尝试使用终端而不是 xcode 本身进行编译。

回答by Jasper Blues

For MacPorts use:

对于 MacPorts 使用:

port select --set gcc <group>, <version>

. . as detailed in this answer.

. . 如本答案所述

For Homebrew use:

对于 Homebrew 使用:

Brew link and brew unlink the package versions that you prefer to use. Note that an "unlinked" package is still installed and usable from /usr/local/opt//, it's just not in the default path.

brew link 和 brew unlink 您喜欢使用的软件包版本。请注意,“未链接”的包仍然可以从 /usr/local/opt// 安装和使用,只是不在默认路径中。

回答by Ilya Verbin

You can install gcc using any ports system (e.g., MacPorts, http://www.macports.org/)

您可以使用任何端口系统(例如 MacPorts、http://www.macports.org/)安装 gcc