Skip navigation

gcc not working?

326 Views 11 Replies Latest reply: Jan 18, 2013 4:13 AM by Wesley212 RSS
johnfromgilroy Level 1 Level 1 (0 points)
Currently Being Moderated
Dec 28, 2012 9:06 PM

Here's my program, written in vim.

 

#include <stdio.h>

 

 

int main(void)

 

 

{

  printf("Hello world!\n");

  return 0;

}

 

I enter:   gcc hello.c

and I get:

 

hello.c:1:19: error: stdio.h: No such file or directory

hello.c: In function ‘main’:

hello.c:6: warning: incompatible implicit declaration of built-in function ‘printf’

 

Why doesn't this work? and How do I get going to writing programs in C?

 

Thanks,

JfromG

iMac, Mac OS X (10.7.1)
  • Jeffrey Jones2 Level 6 Level 6 (8,425 points)
    Currently Being Moderated
    Dec 29, 2012 10:06 AM (in response to johnfromgilroy)

    How did you install gcc? The correct way is in Xcode, Preferences > Downloads > Components > Command Line Tools. If you did it any other way, it is unlikely that gcc is properly installed.

  • VikingOSX Level 5 Level 5 (4,695 points)
    Currently Being Moderated
    Dec 29, 2012 10:36 AM (in response to johnfromgilroy)

    Once you have followed Jeffrey's advice, you will need the following:

     

    #include <stdio.h>

    #include <stdlib.h>

     

    int main(int argc, char * argv[])

    {

     

        return 0;

    }

  • woodmeister50 Level 4 Level 4 (3,690 points)
    Currently Being Moderated
    Dec 29, 2012 10:56 AM (in response to VikingOSX)

    VikingOSX wrote:

     

    Once you have followed Jeffrey's advice, you will need the following:

     

    #include <stdio.h>

    #include <stdlib.h>

     

    int main(int argc, char * argv[])

    {

     

        return 0;

    }

    #include <stdlib.h> not needed for printf, but just good

    a good practice to get into adding it to include list.

     

    The stuff within the parenthesis in int main(int argc, char * argv[])

    is also not needed/required unless the function will have command line

    arguments.  (void) is sufficient in this case.

     

    Ran the code just as he had it on my system without issue.

    His issue is an incomplete or bad install of Xcode.

  • steve359 Level 6 Level 6 (12,035 points)
    Currently Being Moderated
    Dec 29, 2012 10:47 AM (in response to johnfromgilroy)

    Two thoughts to help you ...

     

    There is an excellent (in my not-so-humble-but-so-what opinion) book for C.  "The C Programming Language" written by Dennis Ritchie and Brian Kernighan (the authors of C), ISBN 0-13-110362-8.  $45 on Amazon, $60 through bookstores.  Excellent refrence for C.

     

    It will also explain why these two declarations of "main" are both valid:

     

    main (int argc, char *argv[])

    main (int argc, char **argv)

  • VikingOSX Level 5 Level 5 (4,695 points)
    Currently Being Moderated
    Dec 29, 2012 10:59 AM (in response to woodmeister50)

    Suspected Xcode issue. Yes, we all have some coding pecadillo(s) in our closet. Mine are stdlib and formal main (command-line) syntax.

  • VikingOSX Level 5 Level 5 (4,695 points)
    Currently Being Moderated
    Dec 29, 2012 11:00 AM (in response to steve359)

    The 2012 edition is in its 49th printing. I still have the 1978 original version.

  • steve359 Level 6 Level 6 (12,035 points)
    Currently Being Moderated
    Dec 29, 2012 11:05 AM (in response to VikingOSX)

    Mine is the 1988 printing ... you win!

  • woodmeister50 Level 4 Level 4 (3,690 points)
    Currently Being Moderated
    Dec 29, 2012 11:10 AM (in response to VikingOSX)

    I have the latest printing of K&R because my copy of

    the original was literally disintegrating and was becoming

    a mass of loose pages.

  • steve359 Level 6 Level 6 (12,035 points)
    Currently Being Moderated
    Dec 29, 2012 11:11 AM (in response to woodmeister50)

    It is sad that the newer ones are 50% fatter because the page-stock is heavier.

     

    Or maybe that thin page stock is the reason for yours falling apart.

     

    Mine is very close to losing pages and needing replacement ...

  • Wesley212 Calculating status...
    Currently Being Moderated
    Jan 18, 2013 4:13 AM (in response to johnfromgilroy)

    Has this been solved? If not, would you provide an update of what you have tried?

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.