I am just beginning to try to learn C and have been trying to do tutorials but they won’t compile. The errors seem to suggest it is an issue with me using a 64 bit OS (lion), but I can’t see how that could be the case with such a simple program.
The code: (copied directly from a ‘thenewboston’ tutorial)
#include <stdio.h>
int main(void)
{
printf("Hello World");
getch();
}
I then entered this in terminal:
gcc tnb_1.c
And the error I got was:
Undefined symbols for architecture x86_64:
"_getch", referenced from:
_main in cc2nMvOk.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
The compiler I am using is the standard one installed with xcode.
I am sorry if this question has an obvious answer, but as I can’t get past the first hurdle I am finding it hard to learn anything.
Thank you for your help
Use
getchar()instead ofgetch().getch()is non-standard.Using
getchar()will (probably) mean you need to press enter whereasgetch()does not, but if all you’re trying to do is compile a simple program to get a start with C, that probably doesn’t matter to you.