Different Ways to Setting Up Environment For C++ Programming in Mac
Xcode is an IDE developed by Apple themselves to develop apps for macOS and iOS or all other Operating Systems that Apple develops. It also has support for C/C++ built-in. Here, finding a C++ IDE for a macOS system is quite easy. To run a program in C++ in Mac we have to install Xcode or command-line tools for Xcode.
Hence, there are two options to run a C++ program on Mac.
- Download and install from Apple Appstore
- Download and install by using Command Line Tools and using any preferred IDE or Code Editor for writing C or C++ code.
Way 1: Download and install from Apple Appstore
Note: The macOS version of Visual Studio is not available for C or C++ as we can develop C# but not C/C++.
Step 1: Install Xcode software on the machine on which programs are to be written. So after downloading the Xcode application and later on opening it, you will be greeted by the pop-up as shown below
Step 2: Now click on the link “Create a new Xcode project”.
Step 3: Again, if there is an existing project you will click on “Open a project or file” or “Clone an existing project” if the project is on source control.
Step 4: Click on the macOS tab and then click on the Command-Line app as it the only thing where we can develop apps in C and C++.
Step 5: It will now show an interface to give the product or the app a name and the package name as a normal IDE after giving that name there would be a drop-down to select a language. So, instead of swift, you can select C or C++ and click on the Next button.
Step 6: Then it will ask for the location of the project on your machine, and, done!, you can open or create a C or C++ file now.
Way 2: Installing the Xcode Command Line Tools and using any preferred IDE
In this method, we need to use the Terminal as we need to download and install only some part of Xcode and not the entire Xcode. This method is useful if you have limited storage or for some other reason. We will be downloading the 2GB part of Xcode rather than the entire 28GB Xcode as we only need the C and C++ compiler.
Follow the below step to set up the running environment for C++
Step 1: Open Terminal and type or copy and paste this command “xcode-select –install” and now Xcode Command Line Tools would be installing you will get an interface like this:
Step 2: Now click on Install it will ask for your device password so after entering the password it will install Xcode Command Line Tools. Now we can create a C or C++ file and edit it.
Step 3: Now use VScode or be it else of your choice as it is the best free code and install two extensions for C++.
Note: The first one is C/C++ official extension and the second one is Code runner
Now a C /C++ code can be run in VScode.
Please Login to comment...