Writing, building, and running your C++ on a Mac

The very first wall that I had hit when I was looking for a C++ tutorial was that I struggled finding one that was OS X friendly. Most of the tutorials that I had found started out with installing software onto your PC and then explaining it based on how that program ran. I only have my iMac and Macbook right now (although the Macbook can run Ubuntu as well!), so finding something that would work for me was important. After realizing this initial problem I was seeking out information on how to write and build C++ programs on a Mac.

running c on mac

The first guides that I found said that if you download and install Xcode, which is free to download from the Apple website, you can write and quickly run your C++ code from there. I had installed Xcode ages ago so I got that up and running and ready to receive my code. But for some reason the code I was entering just wasn’t running right! I was getting errors for code that was syntactically correct (as far as I could tell) and I couldn’t understand the errors. Even worse, when I looked up the errors I was receiving the solutions were a little over my head at my current level. I have a half dozen more text editors that do all sorts of things, so I figured that one of them should be able to help me.

The first that I tried was TextWrangler, which I liked A LOT for Python because you could push your code straight to the terminal from the program. Couldn’t manage to get that to work with C++.
After that I tried Komodo Edit, which I also like a lot for its interface. There is an option to view a portion of the editing screen for debugging, and my code was all lit up for strange errors similar to what I was dealing with while running Xcode.
I finally opened Sublime Text 3 although I wasn’t terribly hopeful just because I just don’t use it terribly often. But Sublime Text is how I got my C++ codes to work! I opened up my test.cpp file, made sure again that the syntax was correct and then went to tools > run, which showed a small partition in the bottom of the editing screen and ran my code!

I then wrote a code that required user input, hit run, and was a little disappointed that i wasn’t able to participate with the program, it just skipped over the user input sections. But I instead hit tools > build and ran the executable file that Sublime Text created and it ran perfectly in my Terminal window! It was such a relief!

I apologize if any experienced programmer might look at my excitement and blow it off as me being a complete novice, but for people that are complete beginners just getting a “Hello World” code to run is a huge victory!

Aly Chiman

Aly Chiman is a Blogger & Reporter at AlyChiTech.com which covers a wide variety of topics from local news from digital world fashion and beauty . AlyChiTech covers the top notch content from the around the world covering a wide variety of topics. Aly is currently studying BS Mass Communication at University.