如何在 Mac OS X 10.8 / Xcode 4.4 上使用/安装 gcc
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9353444/
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
How to use/install gcc on Mac OS X 10.8 / Xcode 4.4
提问by Athir Nuaimi
I have install Mountain Lion (Mac OS X 10.8) and now gcc doesn't seem to be available anymore. I've also installed Xcode 4.4 so there is no more /Developer directory.
我已经安装了 Mountain Lion (Mac OS X 10.8),现在 gcc 似乎不再可用。我还安装了 Xcode 4.4,所以没有更多的 /Developer 目录。
I need gcc both for mac ports and for ruby gems (that have native extensions).
对于 mac 端口和 ruby gem(具有本机扩展),我都需要 gcc。
Does Xcode 4.4 include gcc or is there a way to install gcc?
Xcode 4.4 包含 gcc 还是有安装 gcc 的方法?
回答by Steve
Update:
更新:
You can now just run the following command from your terminal:
您现在可以从终端运行以下命令:
xcode-select --install
Starting with Xcode 4.3 - you must now manually install command line tools from Xcode menu > Preferences > Downloads
.
从 Xcode 4.3 开始 - 您现在必须从Xcode menu > Preferences > Downloads
.
Alternatively, there are stand-alone installation packages both for Mountain Lion (10.8)and for Mavericks (10.9).
或者,还有适用于 Mountain Lion (10.8)和Mavericks (10.9)的独立安装包。
This package enables UNIX-style development via Terminal by installing command line developer tools, as well as Mac OS X SDK frameworks and headers. Many useful tools are included, such as the Apple LLVM compiler, linker, and Make.If you use Xcode, these tools are also embedded within the Xcode IDE, and can be installed on your system using the Downloads preferences pane within Xcode 4.3 and later. This package requires Mac OS X 10.7.3 or later.
该软件包通过安装命令行开发工具以及 Mac OS X SDK 框架和头文件,通过终端启用 UNIX 风格的开发。包括许多有用的工具,例如 Apple LLVM 编译器、链接器和 Make。如果您使用 Xcode,这些工具也嵌入在 Xcode IDE 中,并且可以使用 Xcode 4.3 及更高版本中的“下载”首选项窗格安装在您的系统上。此软件包需要 Mac OS X 10.7.3 或更高版本。
回答by Volcanic
I found that after upgrading from Lion my install was failing because it was looking for GCC in /usr/bin/gcc-4.2. Now the default installation path is /usr/bin/gcc.
我发现从 Lion 升级后,我的安装失败了,因为它在 /usr/bin/gcc-4.2 中寻找 GCC。现在默认安装路径是/usr/bin/gcc。
My error looked like this:
我的错误是这样的:
make: /usr/bin/gcc-4.2: No such file or directory
A symlink will sort out the issue:
符号链接将解决问题:
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
回答by Roger Fernandez Guri
Just paste this into terminal:
只需将其粘贴到终端中:
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
I hope that helps!
我希望这有帮助!
回答by Serge Pedroza
pre-1.9.3 Ruby on Mountain Lion
1.9.3 之前的 Ruby on Mountain Lion
Pre-requisites
先决条件
Xcode 4.4,
Xcode Command Line Tools
Homebrew
XQuartz 2.7.2 or later.
rbenv/ruby-build or RVM.
Install GCC
安装 GCC
Note, the Xcode Command Line Tools do not include GCC, they include LLVM-GCC. Same-same, but different.
注意,Xcode 命令行工具不包括 GCC,它们包括 LLVM-GCC。相识又有差别。
$ brew tap homebrew/dupes
$ brew install apple-gcc42
Add the following to your ~/.profile or equivalent:
将以下内容添加到您的 ~/.profile 或等效文件中:
export CC=/usr/local/bin/gcc-4.2
And reload your shell before attempting the install commands below.
并在尝试下面的安装命令之前重新加载您的 shell。
Install RVM
安装 RVM
CFLAGS="-I/opt/X11/include" rvm reinstall ree
Install Ruby
安装红宝石
Prefix the install command with CFLAGS="-I/opt/X11/include"
Then to set your new ruby as default:
然后将您的新 ruby 设置为默认值:
user$ rvm use 1.9.2 --default
Then check your ruby version:
然后检查您的 ruby 版本:
user$ ruby -v
回答by Graham Perrin
For users who can download from Apple a build of Xcode, but not the command line tools
对于可以从 Apple 下载 Xcode 版本但不能从命令行工具下载的用户
An accepted answerto a comparable question suggests kennethreitz / osx-gcc-installer. In that 'OSX GCC Installer' area, the first of two options is pre-built binaries —?for Snow Leopard and for Lion, but not for Mountain?Lion. Considering what's included, I should notrecommend using that project's GCC-10.7-v2.pkg afterinstalling version 4.4 of Xcode on?any build of 10.8.
对类似问题的公认答案表明kennethreitz / osx-gcc-installer。在那个“OSX GCC 安装程序”区域中,两个选项中的第一个是预构建的二进制文件——用于 Snow Leopard 和 Lion,但不适用于 Mountain?Lion。考虑到包含的内容,我不建议在安装 Xcode 4.4 版本后使用该项目的 GCC-10.7-v2.pkg ?任何版本的 10.8。
The more relevant option is build your own, with reference to Apple open sourcefor Developer?Tools.
更相关的选项是构建您自己的,参考Apple的 Developer?Tools开源。
Sources for GCC, compatibility with 10.8
GCC 的来源,与 10.8 兼容
Apple Open Source for the most recently published Developer Tools 4.3is without GCC. The source for GCC in the 4.1area may be too oldfor use with 10.8.
最近发布的开发者工具 4.3 的Apple Open Source没有 GCC。4.1区域的GCC 源可能太旧,无法与 10.8 一起使用。
GCC home pagefor the most recent release.
最新版本的GCC 主页。
Build status for GCC 4.7links to results for x86_64-apple-darwin10.8.0?…
GCC 4.7 的构建状态链接到x86_64-apple-darwin10.8.0 的结果?...
回答by briangonzalez
Apple provides an .mpkg
installer for the Command Line Tools (CLT), but they don't normally expose the link. It includes GCC. You can install it without downloading/installing XCode.
Apple 为.mpkg
命令行工具 (CLT)提供了安装程序,但它们通常不会公开链接。它包括海湾合作委员会。您可以在不下载/安装 XCode 的情况下安装它。
回答by bbaassssiiee
You can compile it yourself with this Makefile. If you want to save yourself 2-5 hours, I created a signed installer package with GCC 4.7.2 for Mac OSX Mountain Lion which you can download here.
你可以用这个 Makefile自己编译它。如果您想节省 2-5 个小时,我为 Mac OSX Mountain Lion 创建了一个带有 GCC 4.7.2 的签名安装程序包,您可以在此处下载。
回答by Pongthep
I'm using OS X 10.9 Mavericks. I only happened to type gcc -v. The system downloaded gcc immediately. Installation completed without Xcode being installed at all. Testing "Hello, world!" works.
我正在使用 OS X 10.9 Mavericks。我只是碰巧输入了 gcc -v。系统立即下载了gcc。安装完成,根本没有安装 Xcode。测试“你好,世界!” 作品。
回答by nbs
You can download the installer(.pkg file) lattest version of GCC for Mountain Lion from this site. You simpy need to download and install it.
您可以从该站点下载最新版本的山狮 GCC 安装程序(.pkg 文件)。您只需要下载并安装它。