PDA

View Full Version : Xcode Beginner Problem




RBrownT
Dec 27, 2011, 06:18 PM
Hi,
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?



robvas
Dec 27, 2011, 06:56 PM
Hi,
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?

Shift-Command-Y will bring up the output window of the debugging console. Your program is probably writing there.

gnasher729
Dec 27, 2011, 06:58 PM
Hi,
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?

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.

robvas
Dec 27, 2011, 07:00 PM
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.

balamw
Dec 27, 2011, 07:00 PM
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.

B

RBrownT
Dec 27, 2011, 07:05 PM
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.)

mmendoza27
Dec 28, 2011, 09:08 PM
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.)

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.

thundersteele
Dec 29, 2011, 12:07 AM
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.