xcode GCC警告“Mac OS X Snow Leopard下内置函数'printf'的隐式声明不兼容”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7904791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:14:01  来源:igfitidea点击:

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

xcodemacosgccosx-snow-leopardgcc-warning

提问by dkrice

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:

在远离 C 编程很长时间之后,我决定再次尝试熟悉它。我正在尝试编译一个 hello.c 程序,但遇到了问题。这是代码:

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

And here's the output from gcc:

这是 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.

我正在使用运行 Snow Leopard (10.6.8) 和 Xcode 3.2.6 的 Mac。

Here's the 'gcc -v' output:

这是'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 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 无法找到位于 /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
$

My LD_LIBRARY_PATH environment variable is:

我的 LD_LIBRARY_PATH 环境变量是:

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

Any help is appreciated.

任何帮助表示赞赏。

Thanks, Keith

谢谢,基思

采纳答案by Paul R

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

您需要重新运行 Xcode 安装程序并检查以下选项UNIX Development

enter image description here

enter image description here

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

如果没有此选项,您仍然可以使用 Xcode,但您将无法获得/usr/includegcc 命令行构建的 etc。

回答by Zan Lynx

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.

您已经为您的特定问题找到了答案,但我出于不同的原因在 OS X 上看到过此问题,因此这可能对其他人有所帮助。

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.

如果您尝试安装 GCC 的自定义编译版本并且它位于 /usr/local/bin 中,或者您已将 PATH 条目添加到 /opt/sw 或类似内容,您可能会收到此错误。

Possible reasons for having the custom GCC but no headers are:

拥有自定义 GCC 但没有标题的可能原因是:

  • 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.)
  • 您试图删除自定义编译版本,但忘记删除 gcc 二进制文件。
  • 您在构建自定义 GCC 时使用了错误的配置选项。
  • 您将头文件安装到错误的目录。(非常类似于最后一个选项。)