Skip to main content
gamedev.net
🔒 Locked

Code compiles in Eclipse but not Xcode?

Started by SirSmash Feb 5, 2010 at 8:34 PM 3 replies 700+ views
Original Post
SirSmash
SirSmash
There's probably an obvious answer as to why this happens, but say I do "Hello World" in Eclipse using C++ using namespace std; int main() { cout << "Hello World" ; return 0; } Spacing and such is missing but the point is that it compiles correctly in Eclipse C++. If I put the same code in Xcode with a new C++ project it fails. Looking up how to do "Hello World" in Xcode using C++ comes up with: int main (int argc, char * const argv[]) { // insert code here... std::cout << "Hello, World!\n"; return 0; } But why the different (and what seems like more complicated) syntax? The books and videos I'm watching explain the code that Eclipse can compile correctly. But seeing that I'd like to make iPhone games I pretty much need to get Xcode working.
Hodgman
Hodgman
The main function is supposed to take two arguments - an "argument count" and an "argument vector".

In your first example, main doesn't take any arguments. Some compilers will accept this and compile anyway, but technically it's incorrect.
Your second example should work on all compilers.

Seeing the main function is only written once for your whole project, once you get it right then this problem shouldn't bother you again for a while ;)


[Edited by - Hodgman on February 6, 2010 1:38:02 AM]
oler1s
oler1s
Quote:
Some compilers will accept this and compile anyway, but technically it's incorrect.
It's not incorrect. Both forms are correct; an implementation that follows the standard must allow for both.

Quote:
If I put the same code in Xcode with a new C++ project it fails.
Really? It fails. How do you know this?
SirSmash
SirSmash
Quote:
Really? It fails. How do you know this?


It's what I was trying, Xcode was coming up with: http://img442.imageshack.us/img442/5015/errortt.png but Eclipse would compile and the program ran. I ended up putting "#include " before the code in Xcode and then it compiles. Apparently Visual Studio needs that as well yet for some reason Eclipse didn't.

Luckily for me the tutorials I'm going through mention things like "#include ", they just mentioned it was only for Visual Studio which got me really confused.
Captain P
Captain P
For iPhone development, Objective-C is the main language. It's possible to use C++, but you will still have to use some Objective-C to interface with the iPhone SDK. If you're just starting out, you may want to ignore C++ for the time being and focus solely on Objective-C.

Bytheway, did you look into Cocos2D already? It's a pretty good library for iPhone game development.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.