HELP ME, please (gcc 4.0 fails)

Discussion in 'Mac Programming' started by I'm a Mac, Apr 19, 2008.

  1. I'm a Mac macrumors 6502

    Joined:
    Nov 5, 2007
    #1
    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.
     
  2. Monkaaay macrumors 6502

    Monkaaay

    Joined:
    Jun 19, 2006
    Location:
    Richmond, VA
    #2
    I would attempt reinstalling Xcode from the iPhone SDK beta 3 download.
     
  3. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #3
    did that, now i have the iPhone sdk back, but it doesn't work.
     
  4. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #4
    When you uninstalled did you make sure to run the uninstall shell script?

    What is the code you trying to compile?
     
  5. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #5
    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;
    }
     
  6. Gelfin macrumors 68020

    Gelfin

    Joined:
    Sep 18, 2001
    Location:
    Denver, CO
    #6
    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.
     
  7. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #7
    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.
     
  8. Gelfin macrumors 68020

    Gelfin

    Joined:
    Sep 18, 2001
    Location:
    Denver, CO
    #8
    (Nevermind, answered my question.)

    What does it say in the Console window?
     
  9. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #9
    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.
     
  10. Gelfin macrumors 68020

    Gelfin

    Joined:
    Sep 18, 2001
    Location:
    Denver, CO
    #10
    When you run the code you describe in the debugger, it should produce something that looks like this in the XCode Console window:

    Code:
    [Session started at 2008-04-20 12:26:43 -0700.]
    [B]Hello, World![/B]
    
    The Debugger has exited with status 0.
    
     
  11. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
  12. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #12
    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?
     
  13. Gelfin macrumors 68020

    Gelfin

    Joined:
    Sep 18, 2001
    Location:
    Denver, CO
    #13
    Didn't you say the build succeeded sometimes? What happens then?
     
  14. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #14
    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
     
  15. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #15
    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.
     
  16. Gelfin macrumors 68020

    Gelfin

    Joined:
    Sep 18, 2001
    Location:
    Denver, CO
    #16
    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.
     
  17. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #17
    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"
     
  18. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #18
    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).
     
  19. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #19
    Looks like its working fine. Exit with status 0 means the program finished successfully and it printed Hello, World for you as well.
     
  20. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #20
    Yea, I realized that prinf meant print to screen, not actually print.
     
  21. lucasgladding macrumors 6502

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #21
    @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.
     
  22. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #22
    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
     
  23. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #23
    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.
     
  24. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #24
    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.
     
  25. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #25
    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.
     

Share This Page