• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Programming with C++ 11 on Mac

Joined
1/14/15
Messages
28
Points
113
First and foremost, try your best to use a window computer. VS is the preferred tool for C++ developing work!!!

Read the following if you REALLY have to use a Mac.
________________________________________________________________
Hi, I figured this might be useful for some folks who would like program with C++ 11 or above on Mac. Although I would suggest using a windows computer instead, which saves you a lot of trouble because things get nasty when it doesn't work on Mac.

Mac has its own default gcc compiler but it's OLD! it's not compatible with some new C++ 11 features. So you would need to update the gcc compiler to a newer version. I used the newest version of Eclipse. Pretty sure X-Code would work similarly.

First, you would need X-Code and command line tools installed. You would also need MacPorts (the one I found working) and Eclipse C++ IDE (Java runtime needed). These are relatively easy to get and install on your Mac.

Up to now, even without doing anything else, you would be able to program and compile with the default compiler.

Here's what you need to do to get C++ 11 work on your Mac.

1. Assuming you have macports correctly installed. In the terminal, type each of the following commands one at a time:
sudo port selfupdate
sudo port upgrade outdated
sudo port install -d gcc47
port select --list gcc


The first two lines ensure that your list is updated. 3rd line would take while because it triggers the download and installation. 4th line returns the available gcc compiler you have on your Mac. You would need to input password since "sudo" is used.

Now from the list you should see "mp-gcc47", then type:
sudo port select gcc mp-gcc47

Note that it doesn't have to be gcc47. Up to now the newest version of gcc is gcc49.

2. Now that you have the compiler ready, next you would need the Eclipse to recognize that compiler. Create a new project in Eclipse. select Cross GCC as your tool chain and use your own project name. Click Next and then Next, put the /opt/local/bin in as the path and NO prefix.

Go to property of the project --> c/c++ build --> settings --> cross gcc compiler and cross g++ compiler. Put -std=c++11 under miscellaneous part of both tabs. Click Apply.

Now go to c/c++ general --> paths and symbols --> # symbols. Select GNU C++. Click Add... Then input GXX_EXPERIMENTAL_CXX0X and everything else can be left blank. Don't forget to click Save before you close it out.

Unless you would take the long way and do this every time, I would keep using the same project for the purpose of this class. Simply delete and add files.

All set. You can use my attached code to see if Eclipse is using the right compiler. It should output the right information (gcc 4.7 or above).
 

Attachments

Last edited:
Regarding platforms for the C++ course, I recommend VS 2013 Community download (it's free).

The goals is to learn C++ as effectively as possible. By all means use Mac whatever but realize that most people use Wintel.

Just saying.
 
Back
Top