For some reason it took me forever to figure out how to use XCode as a C++ compiler. Recently, I figured it out and have worked on several projects without incident.
I needed a compiler to use on my mac because I am currently taking a class on C++ algorithms that uses Microsoft Visual run on Windows. Not surprisingly, Visual doesn’t run on OSX (and it’s frankly too much effort and processing power to install windows on my mac and then run Visual through that. – possible, but unwieldy.)
Frankly, once I started using Xcode for C++. I realized that it’s both simpler and better than Visual anyway. Especially for a new user: I’d rather spend my time and energy working in C++ than trying to figure out a complex compiler. So, without further ado…
1. Install XCode on your machine (it’s huge, so plan accordingly)
2. Open XCode and select File > New Project.
3. Select ‘Command Line Tool’ from OSX > Application
4. Give your New Project a name
5. Click Next and select a location to save your file (desktop / developer folder/ etc.)
6.Your New Project will open and you just need to select main.cpp to get the familiar ‘hello world’ skeleton program.
7. I erase the skeleton and replace it with a simple :
and start from there.
8. In order to to compile and run your program, select Program > Build, correct any errors and Build again if necessary. Then hit the play button in the upper left corner of your window to run the program (intuitive is nice, isn’t it?)
Your program will run, giving you an output window at the bottom of the main window. You may need to click on that window in order to provide input if your program requires it.
I hope this helps you speed along to programming quicker and with less hunting than I had to do. I don’t know why I even tried to find something outside of XCode to start with.