How to Install GCC 4.8 with NetBeans in OS X 10.9

Screen Shot 2014-02-15 at 11.39.21 PM

I tried to update GCC environment in my OS X 10.9 with NetBeans 8 beta environment to use C++11 new features, including shared pointer. There’s some useful information to update using MacPorts, and this article is just my memo.

1. Install Command Line Tools for Xcode

MacPorts’ policies of supporting GCC is as follows, and it must be installed separately from apple site. If this tools not installed, you’ll be failed in the compile operations with some header missing messages.

MacPorts migration policies
http://trac.macports.org/wiki/Migration

Download command line tools for Xcode
https://developer.apple.com/downloads/

2. Install MacPorts and GCC 4.8

Next, install MacPorts normally, and self update to refresh latest package information to your local repository of MacPorts.


$ cd /opt/local/bin
$ sudo ./port self update
$ sudo ./port sync
$ sudo ./port install gcc48
$ sudo ./port install gmake
$ sudo ./port install gcc_select

3. Set the Environment Variables

Set the GCC standard to 4.8 as follows.


$ sudo ./port select --list gcc
Available versions for gcc:
mp-gcc48
none (active)
$ sudo ./port select --set gcc mp-gcc48
Selecting 'mp-gcc48' for 'gcc' succeeded. 'mp-gcc48' is now active.

And set the environment variables to use as the standard gcc as below.


export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/man:$MANPATH

4. Change the NetBeans Settings

Finally stars the NetBeans and open the preferences > C++ > Build Tools, Add GNU_MacPorts and set each compiler path to /opt/local/bin/*.

After finished the global settings, make a new C++ project and open its properties > Build > C++ Compiler > C++ Standard to “C++11”, and compile & run with easy samples.

It seems the NetBeans environment is fine in OS X Mavericks for C++ general programming usage rather than Xcode 5. Of course, it can also use with nice Java EE environment.

Leave a Reply