Xcode Beginner Problem

Discussion in 'Mac Programming' started by RBrownT, Dec 27, 2011.

  1. RBrownT macrumors newbie

    Dec 27, 2011
    I've just barely started (yesterday) experimenting with C++ and it has brought me to Xcode. I've been following a tutorial that seems to be very well written, but sadly, it is mainly directed towards Windows for things such as "Finding an IDE. They did recommend Xcode, and I have gotten to the first program "Hello World!". The problem is that I cannot seem to find out to build and run the code that I have copied and pasted. I've looked around, and there doesn't seem to be very much help up for versions 4.x, so can anyone help me?
  2. robvas macrumors 68020

    Mar 29, 2009
    Shift-Command-Y will bring up the output window of the debugging console. Your program is probably writing there.
  3. gnasher729 macrumors P6


    Nov 25, 2005
    To run your own code: Create a new project using the "Command Line Tool, C++" template: File->New->New Project, then Pick MacOS X, Application, Command Line Tool, Next, change "Type" to C++. This creates a new project with "Hello world" in main.cpp. Command-R to run it.

    In the main window, check what the three buttons above "View" do. The middle own shows/hides the debug/output area.
  4. robvas, Dec 27, 2011
    Last edited by a moderator: Dec 27, 2011

    robvas macrumors 68020

    Mar 29, 2009
    Also, since your Mac is a UNIX machine, you can just work from the terminal. You can also use other text editors such as TextWrangler, Komodo, or SublimeEdit to edit the code, and then compile and run them from the terminal. You don't want to use TextEdit or Word - they could save your program code as a file other than text, which will cause problems.

    Rocket:Documents robert$ cat hello.c
    #include <stdio.h>
    int main(void)
      printf("Hello world\n");
      return 0;
    Rocket:Documents robert$ gcc hello.c -o hello
    Rocket:Documents robert$ ./hello
    Hello world
    If you haven't gotten XCode, you'll have to download it (it's free) from Apple. Check out http://developer.apple.com for more information.
  5. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    You might also try going IDE-less and use gcc/clang directly. (EDIT: robvas beat me to it).

    Learning how to edit, compile, link and execute programs from the command line first is a good skill to learn.

  6. RBrownT, Dec 27, 2011
    Last edited: Dec 27, 2011

    RBrownT thread starter macrumors newbie

    Dec 27, 2011
    Thanks, for the suggestions, if I was going to continue without an IDE, is there and application that comes preloaded on the Mac, and if so, how would I run it from that app? (Sorry, I know it's a noob question.)
  7. mmendoza27 macrumors 6502

    Oct 18, 2007
    Yeah, it's called Terminal. It's basically the command line interface (CLI) that comes with the Mac. It can be found in your Applications > Utilities folder. It's basically like Windows Command Prompt. Have you worked with command line before?

    I'd highly recommend learning how to navigate and run your program in terminal. As a second year CS student, it's just good to know and you don't need all the cruft of a IDE for simple programs. I've had some people in my classes use Eclipse and it just adds complication to what should be your focus, programming syntax and using efficient algorithms.
  8. thundersteele macrumors 68030

    Oct 19, 2011
    I do use Xcode for my small C++ projects, however I just use it as text editor. Then I compile and run my code in the console.

    Xcode is very powerful for GUI development with Cocoa and objective C, but for learning the basics of programming I think it just adds an extra layer of problems.

Share This Page