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

发布于 2024-12-11 22:03:58 字数 1486 浏览 0 评论 0原文

在远离 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏有森光若流苏 2024-12-18 22:03:58

您需要重新运行 Xcode 安装程序并选中 UNIX Development 选项:

在此处输入图像描述

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

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.

放血 2024-12-18 22:03:58

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

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

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

  • 您尝试删除自定义编译版本,但忘记删除 gcc 二进制文件。
  • 您在构建自定义 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:

  • 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.)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文