GCC 警告“内置函数‘printf’的不兼容隐式声明”在 Mac OS X Snow Leopard 下
在远离 C 编程很长一段时间后,我决定再次尝试熟悉它。我正在尝试编译 hello.c 程序,但遇到问题。这是代码:
#include <stdio.h>
main()
{
printf("Hello\n");
}
这是 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’
$
我正在运行 Snow Leopard (10.6.8) 和 Xcode 3.2.6 的 Mac 上工作。
这是“gcc -v”输出:
$ 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 无法找到位于 /Developer/SDKs/MacOSX10.6.sdk/usr/include 中的 stdio.h。想知道如何设置环境变量,这样我就不必在命令行上指定包含路径。当我在命令行上指定它时,我收到另一个错误:
$ 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
$
我的 LD_LIBRARY_PATH 环境变量是:
$ echo $LD_LIBRARY_PATH
/Developer/SDKs/MacOSX10.6.sdk/usr/lib
$
感谢任何帮助。
谢谢, 基思
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要重新运行 Xcode 安装程序并选中
UNIX Development
选项:如果没有此选项,您仍然可以使用 Xcode,但您将无法获得用于 gcc 命令行构建的
/usr/include
等。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.您已经有了针对您的特定问题的答案,但我在 OS X 上因不同原因看到了此问题,因此这可能对其他人有帮助。
如果您尝试安装 GCC 的自定义编译版本并且它位于 /usr/local/bin 中,或者您已将 PATH 条目添加到 /opt/sw 或类似的内容,则可能会出现此错误。
拥有自定义 GCC 但没有标头的可能原因是:
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: