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

#0

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

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

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

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.

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 definitely has the right packages. On 2016-12-26, it had gcc 5 and gcc 6 packages.

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

#1

Installing XCode requires:

  • Enrolling on the Apple website (not fun)
  • Downloading a 4.7G installer

To install g++ *WITHOUT* having to download the MASSIVE 4.7G xCode install, try this package:

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.

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.

#2

Type g++(or make) on terminal.

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

#3

Download Xcode, which is free with an ADC online membership (also free):

http://developer.apple.com/technology/xcode.html

#4

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

Instead of gcc you are using clang, but it works the same.

推荐文章

将参数从Teamcity(属性)传递到命令行

将参数从Teamcity(属性)传递到命令行

推荐文章

获取参数错误编号

获取参数错误编号

推荐文章

boost::asio::deadline_timer在计时器处理程序中完成async_read()和async_write()后未过期

boost::asio::deadline_timer在计时器处理程序中完成async_read()和async_write()后未过期

推荐文章

在返回float更改结果的方法中将结果转换为float

在返回float更改结果的方法中将结果转换为float

推荐文章

如何在eclipse的子项目中调试Intent

如何在eclipse的子项目中调试Intent

推荐文章

如何在rubyonrails中通过点击链接删除记录?

如何在rubyonrails中通过点击链接删除记录?

推荐文章

OSX中的C++全局快捷方式

OSX中的C++全局快捷方式

推荐文章

当其他字符首先需要时,ANTLR匹配字符?

当其他字符首先需要时,ANTLR匹配字符?

推荐文章

为什么对站点的请求返回错误访问控制允许源

为什么对站点的请求返回错误访问控制允许源

推荐文章

在等待来自服务的回调时,当会话超时时通知客户端

在等待来自服务的回调时,当会话超时时通知客户端

推荐文章

CSS选择器,不是

CSS选择器,不是

推荐文章

Struts 1-行提交

Struts 1-行提交

推荐文章

从javaweb服务的操作创建MySql数据库

从javaweb服务的操作创建MySql数据库

推荐文章

在C中初始化字符指针。为什么认为危险?

在C中初始化字符指针。为什么认为危险?

推荐文章

如何使用MonoDroid打开网站?

如何使用MonoDroid打开网站?

推荐文章

无法通过OLE DB连接到Oracle 11g

无法通过OLE DB连接到Oracle 11g