Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

gcc not working?

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)

Posted on Dec 28, 2012 9:06 PM

Reply
11 replies

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.

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)

gcc not working?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.