在远离 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
$
任何帮助表示赞赏。
谢谢,基思