c++11 on MacOS 10.8.5 or even 10.4.11

I tried to compile my c++ code with c++11 features on GCC 4.2.1 which is default on my MacBookPro3,1 with MacOS 10.8.5. I used random library, so I needed newer version of GCC, 4.7 at least to be more precise. I already have MacPorts on this machine (installation guide can be found here). So:

/opt/local/bin/port install gcc5

No I can compile:

/opt/local/bin/g++-mp-5 -std=c++11 main.cpp

Even that you use GCC 5.5.0 you need to pass flag to enable c++11.

If someone thinks that this was too easy, then lets try to do this on MacOS 10.4.11 on PowerBook3,4. First thing is to install XCode 2.5 which suppose to be the last one for 10.4 operating system. You can grab it from xcodereleases.com after signing in with your Apple ID. Install XCode and then download MacPorts 2.8.0. Next, install GCC 5 using same command as previously. This time it will take forever to build it as it has way less powerful hardware than newer MacBookPro3,1. During that time it got so hot so I could not even touch keyboard. Iit was around 50 degrees Celcius while being cooled and over 65 degrees without cooling.

sudo /opt/local/bin/port -f deactivate libunwind-headers
sudo /opt/local/bin/port install apple-gcc42
sudo /opt/local/bin/port install gcc5

Unfortunately GCC 5 is not supported and you need to install GCC 4.8 or at least 4.7. Prepare one day for building libgcc6, another day for libgcc7, one more for GCC itself and half a day for other stuff.

MacPorts installation on 10.8.5

To bring and old MacBookPro up to date you can use MacPorts. First you should download and install MacPorts package from macports.org. There is a pkg file to use specifically for Mountain Lion. That’s the easy one. A little harder would be to grab working XCode with command line tools. You need to have Apple ID, not quite sure if there is different one to access developer.apple.com but mine works just fine.

Go and download XCode 5.1.1 and command line tools, file names are as follows:

MacPorts-2.7.2-10.8-MountainLion.dmg
Xcode_5.1.1.dmg
Command_Line_Tools_OS_X_Mountain_Lion_for_Xcode__April_2014.dmg

XCode requires accepting licence with the following command:

xcodebuild -licence

As you will install command line tools manually, then there is no need to go to XCode’s preferences – Downloads section. Still it would not probably work as Apple ID now requires 2FA which is not present in such and old operating system.

MacPorts itself require update:

sudo /opt/local/bin/port selfupdate

After that you can install various packages. Without updating you are going to have troubles installing things as there will be missing package dependencies. For instance, to install wget type:

sudo /opt/local/bin/port install wget