C++ 如何在 MacOS X 上安装 g++?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2122425/
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 do I install g++ on MacOS X?
提问by Josh Glover
I want to compile C++ code on MacOS X, using the g++ compiler. How do I install it?
我想在 MacOS X 上使用 g++ 编译器编译 C++ 代码。我该如何安装?
回答by Omnifarious
That's the compiler that comes with Apple's XCode tools package. They've hacked on it a little, but basically it's just g++.
这是 Apple 的 XCode 工具包附带的编译器。他们对它进行了一些修改,但基本上它只是 g++。
You can download XCode for free (well, mostly, you do have to sign up to become an ADC member, but that's free too) here: http://developer.apple.com/technology/xcode.html
您可以在此处免费下载 XCode(嗯,大多数情况下,您必须注册才能成为 ADC 会员,但这也是免费的):http: //developer.apple.com/technology/xcode.html
Edit 2013-01-25:This answer was correct in 2010. It needs an update.
编辑 2013-01-25:这个答案在 2010 年是正确的。它需要更新。
While XCode tools still has a command-line C++ compiler, In recent versions of OS X (I think 10.7 and later) have switched to clang/llvm(mostly because Apple wants all the benefits of Open Source without having to contribute back and clang is BSD licensed). Secondly, I think all you have to do to install XCode is to download it from the App store. I'm pretty sure it's free there.
虽然 XCode 工具仍然有一个命令行 C++ 编译器,但在最近的 OS X 版本(我认为 10.7 及更高版本)已经切换到clang/llvm(主要是因为 Apple 希望获得开源的所有好处,而无需回馈,而 clang 是BSD 许可)。其次,我认为安装 XCode 所要做的就是从 App Store 下载它。我很确定那里是免费的。
So, in order to get g++ you'll have to use something like homebrew(seemingly the current way to install Open Source software on the Mac (though homebrew has a lot of caveats surrounding installing gcc using it)), fink(basically Debian's apt system for OS X/Darwin), or MacPorts(Basically, OpenBSDs ports system for OS X/Darwin) to get it.
因此,为了获得 g++,您必须使用homebrew 之类的东西(似乎是当前在 Mac 上安装开源软件的方式(尽管homebrew 有很多关于使用它安装 gcc 的警告))、fink(基本上是 Debian 的 apt OS X/Darwin 系统)或MacPorts(基本上,OS X/Darwin 的 OpenBSD 端口系统)来获取它。
Fink definitely has the right packages. On 2016-12-26, it had gcc 5and gcc 6packages.
Fink 绝对有合适的包。2016 年 12 月 26 日,它有gcc 5和gcc 6包。
I'm less familiar with how MacPorts works, though some initial cursory investigation indicates they have the relevant packages as well.
我不太熟悉 MacPorts 的工作原理,尽管一些初步的粗略调查表明它们也有相关的软件包。
回答by Dave Dopson
Installing XCode requires:
安装 XCode 需要:
- Enrolling on the Apple website (not fun)
- Downloading a 4.7G installer
- 在 Apple 网站上注册(不好玩)
- 下载 4.7G 安装程序
To install g++ *WITHOUT*having to download the MASSIVE 4.7G xCode install, try this package:
要安装 g++ *无需*下载 MASSIVE 4.7G xCode 安装,试试这个包:
https://github.com/kennethreitz/osx-gcc-installer
https://github.com/kennethreitz/osx-gcc-installer
The DMG files linked on that page are ~270M and much quicker to install. This was perfect for me, getting homebrew up and running with a minimum of hassle.
该页面上链接的 DMG 文件约为 270M,安装速度更快。这对我来说非常完美,可以轻松地启动和运行自制软件。
The github project itself is basically a script that repackages just the critical chunks of xCode for distribution. In order to run that script and build the DMG files, you'd need to already have an XCode install, which would kind of defeat the point, so the pre-built DMG files are hosted on the project page.
github 项目本身基本上是一个脚本,它只重新打包 xCode 的关键块以进行分发。为了运行该脚本并构建 DMG 文件,您需要已经安装了 XCode,这有点违背了这一点,因此预构建的 DMG 文件托管在项目页面上。
回答by kobe24
Type g++(or make) on terminal.
在终端上输入 g++(或 make)。
This will prompt for you to install the developer tools, if they are missing.
如果缺少开发人员工具,这将提示您安装它们。
Also the size will be very less when compared to xcode
与 xcode 相比,尺寸也会小很多
回答by Josh Glover
Download Xcode, which is free with an ADC online membership (also free):
下载 Xcode,它是 ADC 在线会员免费的(也是免费的):
回答by All-Purpose Guru
xcode is now available for free from the app store. Just "buy it" (for free) and it will download. To get the command line tools go into preferences/downloads and "install command line compiler tools".
xcode 现在可以从应用商店免费获得。只需“购买”(免费),它就会下载。要获取命令行工具,请进入首选项/下载并“安装命令行编译器工具”。
Instead of gcc you are using clang, but it works the same.
您使用的是clang而不是gcc,但它的工作原理相同。