How do I install g++ on MacOS X?

前端 未结 5 1224
臣服心动
臣服心动 2020-12-09 16:15

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

5条回答
  •  时光取名叫无心
    2020-12-09 16:35

    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.

提交回复
热议问题