GCC warning "incompatible implicit declaration of built-in function ‘printf’" under Mac OS X Snow Leopard
Solution 1
You need to re-run the Xcode installer and check the option for UNIX Development
:
Without this option you can still use Xcode but you will not get /usr/include
etc for gcc command-line builds.
Solution 2
You already have an answer for your particular problem, but I have seen this problem on OS X for a different reason, so this may be helpful to other people.
If you have tried installing a custom compiled version of GCC and it is in /usr/local/bin or you have added a PATH entry to /opt/sw or something similar, you can get this error.
Possible reasons for having the custom GCC but no headers are:
- You tried to remove the custom compiled version but forgot to delete the gcc binary.
- You used the wrong configure options when building the custom GCC.
- You installed the header files to the wrong directory. (Very similar to the last option.)
dkrice
Updated on June 05, 2022Comments
-
dkrice about 2 years
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