Search code examples
xcodemacosgccosx-snow-leopardgcc-warning

GCC warning "incompatible implicit declaration of built-in function ‘printf’" under Mac OS X Snow Leopard


After a very long time away from C programming, I've decided to try and get familiar with it again. I am trying to compile a hello.c program but am having problems. Here's the code:

#include <stdio.h>
main()
{
  printf("Hello\n");
}

And here's the output from gcc:

$ gcc -o hello hello.c 
hello.c:1:19: error: stdio.h: No such file or directory
hello.c: In function ‘main’:
hello.c:4: warning: incompatible implicit declaration of built-in function ‘printf’
$

I am working on a Mac running Snow Leopard (10.6.8) and Xcode 3.2.6.

Here's the 'gcc -v' output:

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
$

gcc is not able to find stdio.h which is located in /Developer/SDKs/MacOSX10.6.sdk/usr/include. Wondering about how to set an environment variable so I don't have to specify the include path on the command line. I get another error when I specify it on the command line:

$ gcc -I/Developer/SDKs/MacOSX10.6.sdk/usr/include -o hello hello.c 
ld: library not found for -lcrt1.10.6.o
collect2: ld returned 1 exit status
$

My LD_LIBRARY_PATH environment variable is:

$ echo $LD_LIBRARY_PATH
/Developer/SDKs/MacOSX10.6.sdk/usr/lib
$

Any help is appreciated.

Thanks, Keith


Solution

  • You need to re-run the Xcode installer and check the option for UNIX Development:

    enter image description here

    Without this option you can still use Xcode but you will not get /usr/include etc for gcc command-line builds.