Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 27, 2011, 06:18 PM   #1
RBrownT
macrumors newbie
 
Join Date: Dec 2011
Xcode Beginner Problem

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?
RBrownT is offline   0 Reply With Quote
Old Dec 27, 2011, 06:56 PM   #2
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
Quote:
Originally Posted by RBrownT View Post
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.
robvas is offline   0 Reply With Quote
Old Dec 27, 2011, 06:58 PM   #3
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by RBrownT View Post
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.
gnasher729 is offline   0 Reply With Quote
Old Dec 27, 2011, 07:00 PM   #4
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
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.

Code:
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.

Last edited by balamw; Dec 27, 2011 at 07:01 PM. Reason: CODE tags
robvas is offline   0 Reply With Quote
Old Dec 27, 2011, 07:00 PM   #5
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
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
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Dec 27, 2011, 07:05 PM   #6
RBrownT
Thread Starter
macrumors newbie
 
Join Date: Dec 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.)

Last edited by RBrownT; Dec 27, 2011 at 07:11 PM.
RBrownT is offline   0 Reply With Quote
Old Dec 28, 2011, 09:08 PM   #7
mmendoza27
macrumors regular
 
Join Date: Oct 2007
Quote:
Originally Posted by RBrownT View Post
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.
__________________
Mac Pro 2.26 8-core, 6GB, 640 GB + 2x1.5 TB, 3 monitors
11" MBA i5, 4GB, 128GB, iPhone 4, iPad, Airport Express/Extreme
mmendoza27 is offline   0 Reply With Quote
Old Dec 29, 2011, 12:07 AM   #8
thundersteele
macrumors 68030
 
Join Date: Oct 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.
thundersteele is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
XCode - How can I have different items in a TableView go to different .xib files? rebello95 Mac Programming 4 Nov 29, 2011 04:20 PM
Need Xcode Help! Buly34 Mac Programming 3 Feb 17, 2011 06:03 AM
Problem with Xcode or Problem with this string of codes? Xcode Beginner OS X 5 May 6, 2010 02:12 PM
xcode beginner ceezy3000 Buying Tips and Advice 3 Mar 16, 2009 12:29 AM
Please help! Xcode beginner! doubleS Mac Programming 1 May 14, 2008 01:34 AM


All times are GMT -5. The time now is 11:35 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC