How to Start Using C++ on Mac

To begin C++ coding on a Mac you can use Apple’s own developer platform: Xcode. This is a free, full featured IDE that’s designed to create native Apple apps. However, it’s also able to be used to create C++ code relatively easily.


Apple’s Xcode is primarily designed for users to develop apps for macOS, iOS, tvOS and watchOS applications in Swift or Objective-C, but we can use it for C++ too.

Step 1 – Start by opening the App Store on your Mac, Apple Menu > App Store. In the Search box enter Xcode, and press Return. There will be many suggestions filling the App Store window, but it’s first option, Xcode, that you need to click on.

Step 2 – Take a moment to browse through the app’s information, including the compatibility to ensure you have the correct version of macOS. Xcode requires macOS 10.12.6 or later to install and work.

Step 3 – When you’re ready, click on the Get or cloud icon button which will install the Xcode app. Enter your Apple ID, and Xcode will begin to download and install. It may take some time depending on the speed of your Internet connection, as Xcode is in excess of 11GB.

Step 4 – When the installation is complete, click on the Open button to launch Xcode. Click Agree to the licence terms, and enter your password to allow Xcode to make changes to the system. When you’ve done that, Xcode will begin to install additional components.

Step 5 – With everything now installed, including the additional components, Xcode will launch displaying the version number along with three choices and any recent projects that you’ve worked on – although for a fresh install, this will be blank.

Step 6 – Start by clicking on Create New Xcode Project, this opens a template window to choose which platform you’re developing code for. Click the macOS tab, then click the Command Line Tool option. Click Next to continue.

Step 7 – Fill in all the fields, but ensure that the Language option at the bottom is set to C++. Simply choose it from the drop-down list. When you’ve filled in the fields, and made sure that C++ is the chosen language, click on the Next button to continue.

Step 8 – The next step asks where to create a Git Repository for all your future code. Choose a location on your Mac, or a network location, and click the Create button. When you’ve done all that, you can start to code. The left-hand pane details the files used in the C++ program you’re coding. Click on the main.cpp file in the list.

Step 9 – You will notice that Xcode has automatically completed a basic Hello World program for you. The differences here are that the int main () function now contains multiple functions and the layout is slightly different. This is just Xcode utilising the content that’s available to your Mac.

Step 10 – When you want to run the code, click on Product > Run. You may be asked to enable Developer Mode on the Mac, this is to authorise Xcode to perform functions without needing your password every session. When the program executes, the output will be displayed at the bottom of the Xcode window.

Find more guides like this in…

David Hayward

David has spent most of his life tinkering with technology, from the ZX Spectrum, getting his hands on a Fujitsu VPP5000/100 supercomputer, and coding on an overheating Raspberry Pi. He's written for the likes of Micro Mart, Den of Geek, and countless retro sites and publications, covering reviews, creating code and bench testing the latest tech. He also has a huge collection of cables.

Related Articles

Back to top button