xcode 如何在 Mac 的终端中使用 g++?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12652701/
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 g++ in terminal in mac?
提问by Cuero
I've installed Xcode and I can compile .cpp files in Xcode. However, I wanna use g++ in Terminal but command not found: g++ now.
My OS is Mountain Lion Xcode version is 4.4.
我已经安装了 Xcode,我可以在 Xcode 中编译 .cpp 文件。但是,我想在终端中使用 g++ 但找不到命令:g++ now。
我的操作系统是 Mountain Lion Xcode 版本是 4.4。
采纳答案by Suhail Patel
You need to download and install the Command Line Tools for OSX Mountain Lion from Apple Developer(you'll need a Apple ID which is free to sign up for). This will install GCC (including g++) so you can build direct from Terminal
您需要从Apple Developer下载并安装 OSX Mountain Lion 的命令行工具(您需要一个可免费注册的 Apple ID)。这将安装 GCC(包括 g++),因此您可以直接从终端构建
The exact package currently is Command Line Tools (OS X Mountain Lion) for Xcode - September 2012
目前的确切软件包是 Xcode 的命令行工具 (OS X Mountain Lion) - 2012 年 9 月
Description about the package from Apple:
Apple 包装说明:
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.5.
该软件包通过安装命令行开发工具以及 Mac OS X SDK 框架和头文件,通过终端启用 UNIX 风格的开发。包括许多有用的工具,例如 Apple LLVM 编译器、链接器和 Make。如果您使用 Xcode,这些工具也嵌入在 Xcode IDE 中,并且可以使用 Xcode 4.5 中的“下载”首选项面板安装在您的系统上。
回答by Jason Molenda
Note that when you run "g++" with Xcode 4.5 installed, you're picking up llvm-g++-4.2 (based on gcc 4.2.1) -- a provided, but no longer supported compiler on the platform. I'd strongly recommend using clang++ instead, the actively supported/developed compiler on the platform.
请注意,当您在安装了 Xcode 4.5 的情况下运行“g++”时,您会选择 llvm-g++-4.2(基于 gcc 4.2.1)——平台上提供但不再支持的编译器。我强烈建议使用 clang++,这是平台上积极支持/开发的编译器。

