PDA

View Full Version : Can't compile Hello world app in Xcode (First foray into mac coding)




NightLord
May 14, 2006, 02:18 PM
I am using a book called "Teach yourself C++" and want to use its first example piece of code to create a basic Hello World app. However, I can't build it, as the Build and Build and go buttons are greyed out.

Here is the code (Sans the irrelevant comments at top):


#include <iostream>

int main();
int main()
{
std::cout << "Hello World!\n";
return 0;
}

Does anyone know why it won't work? The code is copied perfectly from the book. Thanks alot.



robbieduncan
May 14, 2006, 02:55 PM
Did you create a new project or just open the file? Unless you start a project you can't use XCodes compile button. You could just use the command line for something this simple though.

The project type you want is C++ Tool under Command Line Utility

NightLord
May 14, 2006, 03:59 PM
I chose "Make empty project" and added an empty Cpp file

robbieduncan
May 14, 2006, 04:32 PM
That's probably not the easiest way to go (my suggestion is). Does your empty project have any Targets. Without at least one Target you can't compile...

HiRez
May 14, 2006, 05:34 PM
Yeah, something wrong with your project setup, there is nothing wrong with the code. I compiled and ran it in Terminal, no problems. As Robbie says, it's probably much easier to do small, text-only projects like this in TextWrangler/Terminal.

steelphantom
May 14, 2006, 05:36 PM
Here's the easiest way to start a C++ Project in Xcode:

1. Start Xcode, and go to File > New Project > C++ Tool

2. Name/save it

3. Open "main.cpp" and start coding

4. Click "Build and Go" and your project will be compiled

Barring some gross oversight, this should work. :D

slooksterPSV
May 21, 2006, 02:32 AM
I am using a book called "Teach yourself C++" and want to use its first example piece of code to create a basic Hello World app. However, I can't build it, as the Build and Build and go buttons are greyed out.

Here is the code (Sans the irrelevant comments at top):


#include <iostream>

int main();
int main()
{
std::cout << "Hello World!\n";
return 0;
}

Does anyone know why it won't work? The code is copied perfectly from the book. Thanks alot.

I don't know what book you are reading but that's bad coding practice to declare int main(); when int main is the executing function.

EDIT: That's just what I was taught.