PDA

View Full Version : HELP ME, please (gcc 4.0 fails)




I'm a Mac
Apr 19, 2008, 10:19 PM
I have the iPhone SDK installed (with Xcode), and I tried to create a simple hello, world app like it says in the books and whenever I click build, I get this error Command /Developer/usr/bin/gcc-4.0 failed with exitcode

So then, I went to the ADC website, installed xcode 3.0,(without the iPhone SDK), and it still doesn't work

Any ideas? I tried googling, someone else had the problem, but I didn't find any answers.

When I make an app just in interface builder it works.



Monkaaay
Apr 19, 2008, 11:19 PM
I would attempt reinstalling Xcode from the iPhone SDK beta 3 download.

I'm a Mac
Apr 20, 2008, 10:15 AM
did that, now i have the iPhone sdk back, but it doesn't work.

Cromulent
Apr 20, 2008, 10:50 AM
When you uninstalled did you make sure to run the uninstall shell script?

What is the code you trying to compile?

I'm a Mac
Apr 20, 2008, 11:11 AM
When you uninstalled did you make sure to run the uninstall shell script?

What is the code you trying to compile?

I never installed anything. The first time I installed Xcode was when the iPhone SDk came out, since then, I installed all of the updates. When I tried to create the classic "Hello, world" app in objective c, just like all of the books say, I get that error. So then, I went to the ADC website, installed Xcode 3.0, it got rid of the iPhone SDK (or so it looked), and it still didn't work, so I reinstalled the SDK. Interestingly enough, when I create an interface with interface builder, and use the hello, world code for main.m , I don't get a build failed error, but nothing happens, even though it says build succeed. The app doesn't launch, though.

Here's what I've been using:

#import <stdio.h>

int main (int argc, const char *argv[])
{
printf ("Hello, World.\n");
return 0;
}

Gelfin
Apr 20, 2008, 02:21 PM
Interestingly enough, when I create an interface with interface builder, and use the hello, world code for main.m , I don't get a build failed error, but nothing happens, even though it says build succeed. The app doesn't launch, though.

I bet it is doing something; you just aren't seeing it. Try opening the Console window using Cmd-Shift-R in XCode and then doing "Build and Go". You'll probably see the "hello world" message pop up.

You don't see your interface appear because in replacing the default contents of "main.m" you've removed the code that causes that to happen.

No idea why your original attempt would have failed based on your description, though.

I'm a Mac
Apr 20, 2008, 02:22 PM
So why doesn't it print "Hello, World" ?



I looked at the console log when it said the build succeeded. Hello, World did not appear once.

Gelfin
Apr 20, 2008, 02:28 PM
(Nevermind, answered my question.)

What does it say in the Console window?

I'm a Mac
Apr 20, 2008, 02:40 PM
When the build succeeds, it doesn't say anything in the console window. when the build fails it says something like filelist not found... and then the gcc 4.0 error.

Gelfin
Apr 20, 2008, 02:44 PM
When you run the code you describe in the debugger, it should produce something that looks like this in the XCode Console window:

[Session started at 2008-04-20 12:26:43 -0700.]
Hello, World!

The Debugger has exited with status 0.

I'm a Mac
Apr 20, 2008, 02:48 PM
But all I get is the build failed message :(

Cromulent
Apr 20, 2008, 02:59 PM
But all I get is the build failed message :(

Yes but what exactly is the message? Copy and paste it.

What exactly are you doing from start to finish?

So basically you installed the Developer tools in the default location I assume (if not say so) and then just made a standard Command Line Tool project and then put the code in it? Then clicked Build and Go right?

Gelfin
Apr 20, 2008, 02:59 PM
But all I get is the build failed message :(

Didn't you say the build succeeded sometimes? What happens then?

I'm a Mac
Apr 20, 2008, 03:27 PM
it says building, linking, compiling... etc. and then it says CocoaNotePad, (the name of my app) launched.

(Original my hello, world was just displayed in editable text on the screen)

EDIT: I even deleted the interface xib file and it still only says CocoaNotePad launched

Cromulent
Apr 20, 2008, 03:38 PM
it says building, linking, compiling... etc. and then it says CocoaNotePad, (the name of my app) launched.

(Original my hello, world was just displayed in editable text on the screen)

EDIT: I even deleted the interface xib file and it still only says CocoaNotePad launched

Sounds like your application is running then. Open Activity Monitor (just use spotlight) and look for the name of your app in the list of processes. If it is there it is working.

You'll have to use Activity Monitor to kill it though.

Gelfin
Apr 20, 2008, 03:42 PM
it says building, linking, compiling... etc. and then it says CocoaNotePad, (the name of my app) launched.

(Original my hello, world was just displayed in editable text on the screen)

EDIT: I even deleted the interface xib file and it still only says CocoaNotePad launched

I've got to be honest, I'm not getting nearly enough detail out of you to be much help here. You seem to be deeply confused about one or more things, but I cannot even tell what from here.

How about just start over. Pretend we have never used XCode before and, step-by-step, walk us through the process of creating a "Hello, World" project, building it, and checking the output, as you understand that process to work. Include keystrokes, specific strings you see on screen and where you see them and so forth. At the point where you don't see what you expect to see, explain to us in detail what you expected to see.

I'm a Mac
Apr 20, 2008, 08:53 PM
OK, here is my process...

I open up Xcode, and select cocoa application as the template. Next, I double click the main.m file. I change #import <Cocoa/Cocoa.h> to #import <stdio.h>.

after the {, I add printf("Hello, World.\n"), and I change return NSApplicationMain(argc, (const char **) argv); to return 0;
and I leave the }

so my finished code looks like

#import <stdio.h>

int main (int argc, const char *argv[])
{
printf ("Hello, World.\n");
return 0;
}

I then click build, and then save before building.
I now get a message that says: The Debugger has exited with status 0.
[Session started at 2008-04-20 21:51:24 -0400.]
Hello, World.

Why didn't it print "Hello, World"

admanimal
Apr 21, 2008, 12:19 AM
I then click build, and then save before building.
I now get a message that says: The Debugger has exited with status 0.
[Session started at 2008-04-20 21:51:24 -0400.]
Hello, World.

Why didn't it print "Hello, World"

Umm...it did print Hello, World right after it gave you the [Session started...] message. Just in case there is confusion, "printing" in the sense you are dealing with here means displaying the text on the screen (in the console).

Cromulent
Apr 21, 2008, 02:04 AM
I then click build, and then save before building.
I now get a message that says: The Debugger has exited with status 0.
[Session started at 2008-04-20 21:51:24 -0400.]
Hello, World.

Why didn't it print "Hello, World"

Looks like its working fine. Exit with status 0 means the program finished successfully and it printed Hello, World for you as well.

I'm a Mac
Apr 21, 2008, 08:22 AM
Yea, I realized that prinf meant print to screen, not actually print.

lucasgladding
Apr 21, 2008, 10:02 AM
@I'm a Mac:

Tutorials aren't a good place to start if you're trying to build any app for anything more than practice. It's like watching someone build a bridge and calling yourself a civil engineer. Remember that plenty of people spend 5 years in school (often after years as a hobby) to gain any stable knowledge programming. It doesn't take long to get started, but I would recommend at least reading Cocoa Programming for Mac OS X. The new edition is expected to be released next month and can be found at:

http://www.amazon.com/Cocoa-Programming-Mac-OS-3rd/dp/0321503619

If you run into issues with an app from a tutorial, make a note and move on. Sometimes the reason for errors will come to you when you read the next chapter and learn something new. If you are really determined to get it right the first time, start the project over and or reread it more carefully. It's much more likely that you misunderstood something than the author made a mistake. If any new programmer has enough confidence to say that the example code is wrong, you probably need to take yourself down a notch before bothering to continue.

lee1210
Apr 21, 2008, 10:40 AM
To expand on lucasgladding's point:

I think programming is more of an art than a science. There's some cases in very controlled situations that there is truly only one way to solve a problem. Otherwise there are normally an infinite number of solutions to any problem, and none of them are "best". Things like the "most elegant" are completely subjective. Things like "fastest" might be objective, but that might not always be the best solution for the particular instance (i.e. if readability and maintainability of the code was completely sacrificed for execution time, in a case that execution time is not an extremely high priority).

Being able to write code that is safe, accurate, and readable is not something you can get from a book. There are books that will help, but it really takes practice, and honing your skills. It also really helps if someone with more experience can look at your code and tell you what they would change, etc. That's where a place like these forums can be helpful, if you don't have immediate access to programmers with many years of experience otherwise.

As an aside, I learned very little about programming in school. When I finished my degree I was an awful programmer. I knew a lot of theory, how things worked, why things worked, and I could certainly write the code needed to complete projects. However, I would be ashamed to put any code I wrote then on a forum like this now. University taught me to think, and think specifically about computer science, but it did not teach me to program.

I am also going to use this opportunity to again espouse the value of learning command line compilation, execution, and debugging before moving to an IDE. I've been spat at and panned for saying you should use vim as your editor, so use any editor you like, but compile using gcc, debug using gdb (if there are other good debuggers, use those, I'm just most familiar w/ gdb), run your program from the command line. Things will be, I think, much clearer as you progress. There is a time and a place for an IDE, but "Hello, World" is not it.

-Lee

I'm a Mac
Apr 21, 2008, 03:47 PM
I agree with all of you guys. I was just frustrated when I was reading Stephen Kochan's book and nothing was working. The Cocoa book you recommended looked like what I needed. I guess its frustrating in the beginning because programming is like learning a new language. There are all these things you want to say but you don't know how yet.

Cromulent
Apr 21, 2008, 03:50 PM
I agree with all of you guys. I was just frustrated when I was reading Stephen Kochan's book and nothing was working.

Err, it was working as has been shown above.

Stick with the basics, getting a Cocoa book now will just lead to more frustration. Stick to learning Objective-C and when you are comfortable with it you can then go and learn APIs like Cocoa. But don't dive in and expect to be writing a GUI based app straight away. You'll spend a while just doing command line stuff at the start.

I'm a Mac
Apr 21, 2008, 03:59 PM
What exactly is the differnce between Cocoa and objective-c? I'm reading stephen kochan's book programming in objective-c and the only reason I'm using Xcode is because I find it easier than using terminal.

Cromulent
Apr 21, 2008, 04:11 PM
What exactly is the differnce between Cocoa and objective-c? I'm reading stephen kochan's book programming in objective-c and the only reason I'm using Xcode is because I find it easier than using terminal.

Objective-C is the programming language. Cocoa is a set of APIs written in Objective-C. Therefore you need to know Objective-C to understand Cocoa.

Cocoa is not a programming language.

When I say command line stuff, I mean programs which do all there input and output via the Terminal or the Console (same difference really, if you use Xcode it'll be via the console 9 times out of 10).

lee1210
Apr 21, 2008, 04:15 PM
Use the terminal! USE IT! Don't make things worse for yourself by trying to learn the IDE at the same time. You will never be hurt by knowing how to compile and run from the command line.

Explaining the difference between objective-C and cocoa now might not make any sense, but:
Objective-C is a programming language. It is a proper superset of the C programming language. A programming language defines a syntax that can be lexically analyzed, parsed, and have code generation performed by a compiler for that language. For scripting languages the parsing/code generation are one step, but that's not particularly significant. The language does not define anything other than what is valid syntax/grammer. Any "tools" are defined separately. For C there are standard libraries. For objective C there if the Foundation framework. Those provide very commonly used, well tested tools for you to use, but they are not part of the language itself.

Cocoa is an API for OS X. An API is an Application Programming Interface. This defines a standard method of accessing an environment. In this case, the environment is OS X. The API will provide standard methods, objects (in the case of object-oriented languages), etc. that you use to interface with the environment. These are things like displaying windows, or asking the OS for a resource. An API is provided for a particular language. There are sometimes bridges built from other languages. This is the case with Ruby, for example, on OS X. There is a bridge from the Ruby programming language to the Objective-C programming language to access the Cocoa API from Ruby. An API is more likely to change than a programming language as the platform to which it interfaces matures.

So if you wanted building blocks:
C is the basic language syntax used for Objective-C.
Objective-C is the programming language used by Apple APIs.
Cocoa is the standard API for building modern programs on the OS X platform.

I would say you should learn C first, but starting with Objective-C shouldn't be too bad.

Some other notes:
gcc is the compiler for C/Objective-C. It can be used from the command line, or it is invoked for you by XCode.

Cocoa API documentation can be found here:
http://developer.apple.com/referencelibrary/GettingStarted/GS_Cocoa/index.html

Good luck. I would recommend you start simple. Learn to run before you learn to walk, learn to add before you learn to integrate, etc.

-Lee

drastik
May 29, 2009, 06:28 PM
This thread is long dead, but for what it's worth, I get that -filelist linking error if any directory above my project has a comma in the filename. Probably happens with any unusual characters as the path seems to break right at the comma.