Plain C++ programming on a Mac?

Started by
5 comments, last by guyver23 17 years, 6 months ago
Greetings! I have a new Macbook and I am looking to set it up for some C++ programming on the go. I know that Apple has made many fancy things like Cocoa for developing on Mac, but I don't want to learn any of that stuff yet. What I would like is an easy way to hone my basic C++ skills. I am trying to learn how to use the Terminal, and if there are commands needed for that, I would be fine putting them in. Thanks to anyone who can help. =)
Advertisement
Well, best resource for development on the Mac is the Apple Developers Connection. There, they have the MPW, Macintosh Programmer's Workshop. They have a few C++/C compilers, I believe. This would be my prime choice (I have a MacBook Pro, and I use Cocoa).

I found Leonardo IDE by googling "mac "C++" compilers."

Good luck.
D. "Nex" ShankarRed Winter Studios
After (or maybe even before) installing Xcode, you have gcc, the standard *nix C/C++ compiler available. You can even install Emacs and go at it traditional unix-style using the command line, in which case nearly any Linux or Unix programming tutorial will work for you step-by-step.

Xcode can be downloaded, but the version on your install DVD works fine. I wouldn't really recommend Xcode for beginners, but it does install all the tools you need.
if the mac os you have is osx then you already have a c++ and c compiler -> gcc g++

the come preinstalled find a good plain text editor and you are off going with any console or *nix based c++ tutorials
0))))))>|FritzMar>
Hey guyver23,

Most native mac programming is done in a set of apis called Cocoa, or if you came along a few years earlier in Carbon. Cocoa is built on Objective-C (in fact it is the evolution of the NextSTEP framework in Apple's vision), while Carbon is build on C. You can also use the Java bindings (apple provided) to Cocoa as well.

For C++ stuff you don't really have too many choices to get to the system. You can either go for a platform idependant api like SDL or WXWidgets, or you can use the in build bindings using Objective-C++ or the C apis.

I recommend you use the C APIs if you're only doing very little things, no real UI stuff, and the like. Otherwise Objective-C++ is the way to go. You can learn Objective-C from the apple documentation, no textbooks required, and objective-c++ is basically the same only it allows you to call C++ objects from objective-c objects and vice versa.

XCode is the easiest way to write mac programs on mac os (unless your prepared to fork out cash;) But if you just want to write bsd or pure c++ programs then any gcc tutorial will do the trick (and yes, gnu make is present). BSD programs can of course only be executed from the cmd line, but I'm sure you already know that anyway. Emacs isn't particularly nice on mac os anyway (even Aquamacs still has scroll bar 'issues') but if you already know it, grab Aquamacs Emacs which is arguably the best port to mac os.

Hope that helps a little.

Lorenz
If you just want to do C++ and the Terminal, it'll be pretty easy. Download the developer kit from http://developer.apple.com. You'll have to register, but it's free. Once you install that, you can use Xcode to do your C++ or you can just use the Terminal. So if you want to test out using the terminal, it's pretty easy for standard C++. Just write up some program like this in text edit or any other text program (to be completely in the Terminal, you could even use pico)

#include <iostream>using namespace std;int main( int argc, char *argv[] ){    cout << "Hello World" << endl;    return 0;}


Save it somewhere on your computer. Now pull up a Terminal window. Navigate to wherever you saved it. To do that (I don't know how much *nix you know), you use the cd (change directory) command. If you ever need help with commands in the Terminal, just type "man X" where X is the command you want information about. For example "man cd" without the quotes will tell you all about the cd commands.

So assuming your file is on the desktop, when you pull up the Terminal window, just type "cd Desktop" and hit enter. To verify your file is there, type ls to list the contents of the folder. If you see your file, we're in good shape.

Now to compile the program into something you can run type "g++ helloworld.cpp -o HelloWorld". Obviously you would use the name of your file instead of helloworld.cpp. The -o HelloWorld part names the outputted app so you can also change that to -o ILikeToEatTonsOfPizza and it'll work just fine.

Assuming that you've made it this far, all that's left is running the app. To do that you just use the ./ command so if you named it HelloWorld when compiling, just type "./HelloWorld" into the Terminal to see the output from your file.

Hopefully this helped. If you need anything else, let me know via the boards, email, or AIM. I love helping new Mac programmers.
Thanks for all of the help! As it turns out, gcc is NOT installed on Mac OSX by default--it comes with XCode, just like everything else. I love the terminal (I've made my black and green for nostalgia)! Mac OSX comes with Emacs, Nano and Vi by default. I've messed around with them a bit, and I think I will be developing in Nano and Vi (Emacs key-combinations don't suite my style).

Again, thanks! I will get into Mac development later, but I am trying to learn about Unix and polish my C++ skills at the same time so that I will be ready for next semester's class on advanced C++. =)

This topic is closed to new replies.

Advertisement