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

时间:2021-10-11 06:59:07

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.

我正在开发一个运行Mac的雪豹(10.6.8)和Xcode 3.2.6。

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找不到stdio。h位于/Developer/SDKs/ macosx10.6 sdk/usr/include。想知道如何设置环境变量,以便不必在命令行中指定包含路径。当我在命令行中指定它时,会得到另一个错误:

$ 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

谢谢你,基思

2 个解决方案

#1


3  

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

您需要重新运行Xcode安装程序,并检查UNIX开发的选项:

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

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

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

#2


3  

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中,或者您添加了一个路径条目到/opt/sw或类似的东西,您可以得到这个错误。

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

有自定义GCC但没有header的可能原因是:

  • You tried to remove the custom compiled version but forgot to delete the gcc binary.
  • 您试图删除自定义编译版本,但忘记删除gcc二进制文件。
  • You used the wrong configure options when building the custom GCC.
  • 在构建自定义GCC时,您使用了错误的配置选项。
  • You installed the header files to the wrong directory. (Very similar to the last option.)
  • 将头文件安装到错误的目录。(与最后一个选项非常相似。)

#1


3  

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

您需要重新运行Xcode安装程序,并检查UNIX开发的选项:

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

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

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

#2


3  

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中,或者您添加了一个路径条目到/opt/sw或类似的东西,您可以得到这个错误。

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

有自定义GCC但没有header的可能原因是:

  • You tried to remove the custom compiled version but forgot to delete the gcc binary.
  • 您试图删除自定义编译版本,但忘记删除gcc二进制文件。
  • You used the wrong configure options when building the custom GCC.
  • 在构建自定义GCC时,您使用了错误的配置选项。
  • You installed the header files to the wrong directory. (Very similar to the last option.)
  • 将头文件安装到错误的目录。(与最后一个选项非常相似。)