简体   繁体   English

如何在Mac OS X 10.8 / Xcode 4.4上使用/安装gcc

[英]How to use/install gcc on Mac OS X 10.8 / Xcode 4.4

I have install Mountain Lion (Mac OS X 10.8) and now gcc doesn't seem to be available anymore. 我已安装Mountain Lion(Mac OS X 10.8),现在gcc似乎不再可用了。 I've also installed Xcode 4.4 so there is no more /Developer directory. 我还安装了Xcode 4.4,因此没有更多/ Developer目录。

I need gcc both for mac ports and for ruby gems (that have native extensions). 我需要gcc用于mac端口和ruby gems(具有本机扩展)。

Does Xcode 4.4 include gcc or is there a way to install gcc? Xcode 4.4是否包含gcc或有没有办法安装gcc?

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. 该软件包通过安装命令行开发人员工具以及Mac OS X SDK框架和标头,支持通过终端进行UNIX风格的开发。 Many useful tools are included, such as the Apple LLVM compiler, linker, and Make. 包括许多有用的工具,例如Apple LLVM编译器,链接器和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. 如果您使用Xcode,这些工具也嵌入在Xcode IDE中,并且可以使用Xcode 4.3及更高版本中的“下载”偏好设置面板安装在您的系统上。 This package requires Mac OS X 10.7.3 or later. 此程序包需要Mac OS X 10.7.3或更高版本。

I found that after upgrading from Lion my install was failing because it was looking for GCC in /usr/bin/gcc-4.2. 我发现从Lion升级后我的安装失败了,因为它在/usr/bin/gcc-4.2中寻找GCC。 Now the default installation path is /usr/bin/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

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! 我希望有所帮助!

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. 注意,Xcode命令行工具不包括GCC,它们包括LLVM-GCC。 Same-same, but different. 相识又有差别。

$ 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 安装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

For users who can download from Apple a build of Xcode, but not the command line tools 对于可以从Apple下载Xcode的用户而不是命令行工具的用户

An accepted answer to a comparable question suggests kennethreitz / osx-gcc-installer . 对类似问题的接受答案表明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. 在那个'OSX GCC安装程序'区域,两个选项中的第一个是预构建的二进制文件 - 用于Snow Leopard和Lion,但不适用于Mountain Lion。 Considering what's included, I should not recommend using that project's GCC-10.7-v2.pkg after installing version 4.4 of Xcode on any build of 10.8. 考虑到包含的内容,我建议在任何版本的10.8上安装4.4版本的Xcode 之后使用该项目的GCC-10.7-v2.pkg。

The more relevant option is build your own , with reference to Apple open source for Developer Tools. 更相关的选项是构建自己的选项,参考Apple Developer for Developer Tools。

Sources for GCC, compatibility with 10.8 GCC的来源,与10.8的兼容性

Apple Open Source for the most recently published Developer Tools 4.3 is without GCC. 最近发布的Developer Tools 4.3的 Apple Open Source没有GCC。 The source for GCC in the 4.1 area may be too old for use with 10.8. 4.1区域中GCC的来源可能太旧而无法与10.8一起使用。

GCC home page for the most recent release. 最新发布的GCC主页

Build status for GCC 4.7 links to results for x86_64-apple-darwin10.8.0 GCC 4.7的构建状态链接到x86_64-apple-darwin10.8.0的结果 ...

Apple provides an .mpkg installer for the Command Line Tools (CLT), but they don't normally expose the link. Apple为命令行工具(CLT)提供.mpkg安装程序,但它们通常不会公开链接。 It includes GCC. 它包括GCC。 You can install it without downloading/installing XCode. 您可以在不下载/安装XCode的情况下安装它。

Download Command Line Tools w/ GCC here. 在此处下载带GCC的命令行工具。

You can compile it yourself with this Makefile . 您可以使用此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 . 如果你想节省2-5个小时,我为Mac OSX Mountain Lion创建了一个带有GCC 4.7.2的签名安装程序包, 你可以在这里下载

You can download the installer(.pkg file) lattest version of GCC for Mountain Lion from this site. 您可以从此站点下载Mountain Lion的安装程序(.pkg文件)lattest版本。 You simpy need to download and install it. 您需要下载并安装它。

https://github.com/kennethreitz/osx-gcc-installer/downloads https://github.com/kennethreitz/osx-gcc-installer/downloads

I'm using OS X 10.9 Mavericks. 我正在使用OS X 10.9 Mavericks。 I only happened to type gcc -v. 我只碰巧输入了gcc -v。 The system downloaded gcc immediately. 系统立即下载了gcc。 Installation completed without Xcode being installed at all. 安装完成后根本没有安装Xcode。 Testing "Hello, world!" 测试“Hello,world!” works. 作品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM