Guys, question about C++ programming

Discussion in 'General Mac Discussion' started by Abstract, Apr 21, 2005.

  1. Abstract macrumors Penryn

    Abstract

    Joined:
    Dec 27, 2002
    Location:
    Location Location Location
    #1
    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! ;)
     
  2. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    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.
     
  3. Simon Liquid macrumors regular

    Joined:
    Jul 4, 2001
    Location:
    Iowa
    #3
    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.
     
  4. Abstract thread starter macrumors Penryn

    Abstract

    Joined:
    Dec 27, 2002
    Location:
    Location Location Location
    #4
    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. :)
     
  5. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #5
    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.

    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.
     
  6. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #6
    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
     
  7. dxm113 macrumors member

    Joined:
    Jan 22, 2005
    #7

Share This Page