How can I compile in Xcode?

I'm obviously very new at this. I don't know how to compile my Hello World C++ code. Every option in the Build menu is disabled except for Allow ZeroLink. I'm extremely frustrated. I used TurboC before in Windows when I was studying C and though it's primitive-looking, it worked for me. Now, studying C++ is such a pain because the first code that I want to compile doesn't work. I tried Eclipse and used their own Hello World code and yet, Eclipse said "'cout' was not declared in this scope." then for iostream, it said "no such file or directory." What to do??? Which compiler to use so I could get over Hello World?

PowerBook G4, Mac OS X (10.4.10), 1 GB RAM

Posted on Jul 18, 2007 8:31 PM

Reply
8 replies

Jul 19, 2007 5:25 AM in response to Lady777

I'm obviously very new at this. I don't know how to
compile my Hello World C++ code. Every option in the
Build menu is disabled except for Allow ZeroLink.

```````````
Hi Lady777 ~

I suspect you chose either "New File" or "New Empty File" from XCodes's File menu instead of "New Project".
Choose "New Project" from the File menu, then from the options, scroll down to the "Command Line Utility" section and choose the "C++Tool" from the list to create a simple C++ Hello World program. This will create a project that will add the necessary files to create the program.
Click on the "main.cpp" file to edit it. The "Build" menu will be enabled then.

Hope that gets you started. 🙂

iMac G5, PowerBook G4, PowerMac 8500, Mac SE Mac OS X (10.4.10)

Jul 19, 2007 6:37 AM in response to Lady777

I always recommend that people use the command line tools when learning. Xcode, like TurboC, does so much for you that you never really know what is going on behind the scenes. I am not saying you should use the command line for years, just a couple of weeks. Once you get to a point where your programs are too big to use the command line, then you move to Xcode or makefiles.

In the command line (AKA Terminal).
Use vi to create your source file.
Use gcc (or g++ if using C++) to compile it.
Run it from the command line.

This way, you can focus on learning the language instead of wondering why cout doesn't work for you because you never learned about namespaces or include paths because some IDE "took care of that".

Jul 23, 2007 10:59 AM in response to tele_player

You remember TurboC!?


Yes, but I didn't fully disclose. I actually used Turbo Pascal much more than TurboC 🙂

The Borland stuff was really nice for its time - very
fast compilers, and lots of paper documentation.
Loved it!


I completely agree. I still have a copy of Borland C++ Builder. The Xcode and IB developers could learn a thing two there.

Then MS won the war.


I'm not entirely sure about that. On the Mac, I definitely know what my development environment is going to look like for the next few years. However you may feel about Xcode, it is fairly useable and generally not unpleasant. Personally, I'm quite happy with it. On Windows, I have no idea what I'm going to use.

VC++ with those funky .NET C++ extensions? (.NET is much better than MFC, but MS doesn't use it for themselves) C#? (I've never used it)

VB? (I think MS is killing it in favor C#)

Java/J++? At least with Java I could use Eclipse and have Linux compatibility.

All in all, I'm not even sure I will be doing any Windows development in the future. And I can't really say that bothers me much:)

Jul 23, 2007 1:23 PM in response to tele_player

I've never done much code for Windows (a few helper
.dll's), and most of my work was on Solaris, and some
embedded stuff. Pre-Windows, I played around with
Borland stuff on DOS. I'm fairly certain I'll never
take a job doing Windows programming.


That sounds familiar. I did get a chance to do one big Windows project in MFC on NT. It was fun. I've definitely learned a thing or two from Windows. With anything that big, there are a few bright points. I do like Win32 synchronization primitives. It puts pthreads to shame.

For Macs, Xcode is fine. Not perfect, but perfectly
usable.


People forget though - you don't have to use Xcode. Grab a 20 year old UNIX C programming book and type in the problems. In my opinion, that is the best way to get started with modern Mac programming.

Jul 23, 2007 6:39 PM in response to etresoft

People forget though - you don't have to use Xcode.
Grab a 20 year old UNIX C programming book and type
in the problems. In my opinion, that is the best way
to get started with modern Mac programming.


Absolutely, I'm a vi and gcc guy anyway, and I still consider K&R to be one of the best books on programming ever written. I've got several copies, acquired over the past 20+ years.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How can I compile in Xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.