如何在 MacOS X 上安装 g++?

2022-01-23 00:00:00 macos g++ c++

我想在 MacOS X 上使用 g++ 编译器编译 C++ 代码.如何安装?

I want to compile C++ code on MacOS X, using the g++ compiler. How do I install it?

推荐答案

这是苹果XCode工具包自带的编译器.他们已经破解了一点,但基本上它只是 g++.

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++.

您可以在此处免费下载 XCode(嗯,大多数情况下,您必须注册成为 ADC 成员,但这也是免费的):http://developer.apple.com/technology/xcode.html

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

编辑 2013-01-25:这个答案在 2010 年是正确的.它需要更新.

Edit 2013-01-25: This answer was correct in 2010. It needs an update.

虽然 XCode 工具仍然有一个命令行 C++ 编译器,但在最近的 OS X 版本(我认为是 10.7 及更高版本)中已切换到 clang/llvm(主要是因为 Apple 想要开源的所有好处而无需回馈,并且 clang 是 BSD 许可的).其次,我认为安装 XCode 所需要做的就是从 App Store 下载它.我很确定那里是免费的.

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.

因此,为了获得 g++,您必须使用 homebrew 之类的东西(似乎是当前的安装方式Mac 上的开源软件(尽管 homebrew使用它安装 gcc 有很多注意事项)),fink(基本上是 Debian 的 apt 系统OS X/Darwin)或 MacPorts(基本上是 OS X/Darwin 的 OpenBSDs 端口系统)来获取它.

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.

Fink 肯定有合适的软件包.在 2016-12-26,它有 gcc 5 和 gcc 6 包.

Fink definitely has the right packages. On 2016-12-26, it had gcc 5 and gcc 6 packages.

我对 MacPorts 的工作原理不太熟悉,尽管一些初步的粗略调查表明他们也有相关的软件包.

I'm less familiar with how MacPorts works, though some initial cursory investigation indicates they have the relevant packages as well.

相关文章