Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Abstract

macrumors Penryn
Original poster
Dec 27, 2002
24,837
850
Location Location Location
I tried searching, honestly, but I'm such a novice that I need to ask you a seemingly stupid question. Here it is: how do I program in C++ on a Mac?

My background: I learnt how to program on a sorta fake teaching language called "Turing," in highschool, which wasn't a bad way to teach me now that I think back. Since then I've learned how to program in C and Matlab, but that was some semi-basic stuff and only for a few months for a class in Uni.

But here's the funny thing: I don't know anything about programming! I need to learn C++ to program Geant 4 Monte Carlo code. I don't even know what to use to program with? I mean, where do I type the code? What do I have to download so that I can type the code into it and compile it? Is there a basic screen somewhere in OSX that lets me type in some programming code in C++ or a bunch of different programming lanugages, and then later allows me to use the proper compiler to compile it??

The only thing I found when searching is something about XCode and Project Builder and G++. Project Builder sounds right because of its name. :eek: Can this stuff be found for free, or is it something that another company charges for? I just need to fiddle with it using a C++ Programming book that I'll purchase later to help me learn.

I need this thing to tell me if I've made a syntax error and stuff like that, because I know I'll be doing that heaps! ;)
 

HexMonkey

Administrator emeritus
Feb 5, 2004
2,240
504
New Zealand
Xcode (which was renamed from Project Builder) is part of Apple's developer tools, and will compile (among other things) C++. The developer tools are free, and come on a separate CD with Mac OS X. Alternatively, you can sign up for a free Apple Developer Connection account and download them there.
 

Simon Liquid

macrumors regular
Jul 4, 2001
223
0
Iowa
Xcode is the successor to Project Builder. It's an IDE (integrated development environment) that brings together many of the elements to make an application program for OSX. If you want to make Mac apps, you'll certainly want to use this but it's not necessarily the best place to learn a programming language from the beginning.

g++ is the command line compiler for c++. One of the things Xcode does is act as a front end for it, but you can use it by itself as well. If g++ is on your system, you can run it by running the 'Terminal' program (in your Utility folder) and typing 'g++ <…>' where <…> is whatever parameter's you're running the program with. You can type 'man g++' in the terminal to see the manual for it, but a good tutorial might be more helpful.

A lot of platform independent computer language primers assume that you are writing your programs in a generic text editor and compiling them on the command line. I used a book like that when I learned C and it worked pretty well-when you learn a language it helps if you don't have to learn a specialized API at the same time (first I tried to dive in with a book about Cocoa).

Fortunately, all of this stuff is free. In fact, you probably already have them. If you bought Panther, you have a CD of developer's tools, otherwise check the disks that came with your computer, it's on them. The latest versions can always be downloaded from http://developer.apple.com/ - you'll need to sign up as a Mac developer to get it but there's a free option.
 

Abstract

macrumors Penryn
Original poster
Dec 27, 2002
24,837
850
Location Location Location
So I can use XCode to program simple programs to try out what I learn from the book and then compile them and see if I'm doing everything right? That's all I want to do anyway. I just want to see if I'm doing things correctly.

From what you're both saying, I don't need G++ unless I'm planning to program using TextEdit or something, right? G++ is just the compiler if I'm writing code in a .txt file?

And yes, now I noticed the 3rd Panther upgrade disk I got. Maybe I'll wait for Tiger and just install it then. I may do a clean install.

Does XCode tell me if my syntax is wrong? :confused:

Anyway thanks. I didn't know it was going to be this simple and that I already had the tools necessary to program. :)
 

HexMonkey

Administrator emeritus
Feb 5, 2004
2,240
504
New Zealand
Abstract said:
So I can use XCode to program simple programs to try out what I learn from the book and then compile them and see if I'm doing everything right? That's all I want to do anyway. I just want to see if I'm doing things correctly.

Yes. The disadvantage of Xcode is that it is quite an advanced tool so can be difficult to get used to. For example, when you create a new project it lists about 50 different types (you'll probably want to use "C++ Tool", in the "Command Line Utility" section). However, once you get used to it, it can be very useful.

Abstract said:
Does XCode tell me if my syntax is wrong? :confused:

Yes, it will report errors and warnings when you compile. It also has features such as syntax colouring and code completion which might be useful to you.
 

Westside guy

macrumors 603
Oct 15, 2003
6,340
4,158
The soggy side of the Pacific NW
If you're writing simple programs, you might actually find it easier to code in a simple text editor that does syntax highlighting; then do the actual building from the command line. It's probably because I'm just impatient - but I never have liked having to learn integrated development environments. Of course being 44, I learned this stuff prior to IDEs even existing. :D

Some of the free text editors that do this are TextWrangler , subethaedit, and my old X11-based favorite - nedit
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.