我遇到的问题似乎是由gcc找不到它附带的标题引起的。我不太了解C / GCC,我想我会检查编译器应该始终能够找到那些头是否安全。也许设置-I参数会覆盖这个?还是其他什么时髦的?
原始问题出现在github上的shoes中。
你好!我已经尝试在10.8上构建,使用非llvm gcc,如下所述 其他问题,并通过调整rakefile来获取正确的 sdk在正确的地方。BUT
它仍然无法编译。
这是错误报告的开头(它真的很长)
new-host-2:shoes benjamingattet$ rake gcc -I. -c -o shoes/app.o -Wall -I/usr/local/include -I/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.0.0 -I/usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1 -I/usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/x86_64-darwin12.0.0 -O -DRUBY_1_9 -DSHOES_QUARTZ -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -fpascal-strings -Os -w -pipe -march=core2 -msse4.1 -mmacosx-version-min=10.8 -fno-common -x objective-c -fobjc-exceptions -isysroot /Developer/SDKs/MacOSX10.8.sdk -arch x86_64 shoes/app.c shoes/app.c:5:18: error: glib.h: No such file or directory In file included from shoes/app.c:6: ./shoes/app.h:13:19: error: cairo.h: No such file or directory In file included from /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby.h:32, from ./shoes/app.h:14, from shoes/app.c:6: /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:48:21: error: string.h: No such file or directory /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:58:21: error: stdint.h: No such file or directory /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:61:23: error: inttypes.h: No such file or directory /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:64:20: error: stdarg.h: No such file or directory /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:65:19: error: stdio.h: No such file or directory In file included from /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby/ruby.h:67, from /usr/local/Cellar/ruby/1.9.3-p194/include/ruby-1.9.1/ruby.h:32, from ./shoes/app.h:14,
答案 0 :(得分:5)
gcc有一个内置的搜索目录列表。像stddef.h
这样的文件应该在其中一个目录中。获取该列表的一种方法是使用--verbose编译文件(甚至是空文件)。例如,这里给出:
$ touch foo.c
$ gcc --verbose -c foo.c
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
COLLECT_GCC_OPTIONS='-v' '-c' '-mtune=generic'
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/cc1 -quiet -v foo.c -D_FORTIFY_SOURCE=2 -quiet -dumpbase foo.c -mtune=generic -auxbase foo -version -fstack-protector -o /tmp/cc2QEK5o.s
GNU C (Ubuntu 4.4.3-4ubuntu5.1) version 4.4.3 (x86_64-linux-gnu)
compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed
/usr/include
End of search list.
GNU C (Ubuntu 4.4.3-4ubuntu5.1) version 4.4.3 (x86_64-linux-gnu)
compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 462394bb0ac77cba16b6fb6b32589358
COLLECT_GCC_OPTIONS='-v' '-c' '-mtune=generic'
as -V -Qy -o foo.o /tmp/cc2QEK5o.s
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.20.1-system.20100303
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../:/lib/:/usr/lib/:/usr/lib/x86_64-linux-gnu/
COLLECT_GCC_OPTIONS='-v' '-c' '-mtune=generic'
您感兴趣的部分
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed
/usr/include
End of search list.
你可以看到内置路径有一些非现有目录,然后是两种include指令的现有目录列表。
如果gcc安装在不同于编译它的位置,那么它曾经有问题。但ISTR认为最近的gcc在这种情况下更加强大,并从可执行路径开始。
至少你知道gcc在哪里寻找文件,你可能会试着理解他们为什么不在那里。
请注意,gcc没有完整的C库,只提供了与stddef.h
和stdarg.h
等实现密切相关的几个标题。
答案 1 :(得分:1)
GCC不附带这些文件。
您似乎缺少提供这些标头的相关软件包,例如glib2-devel和glibc-devel(或Max OS X使用的任何软件包命名约定),或者您没有将标头放在{{1您使用/Developer/SDKs/MacOSX10.8.sdk
-isysroot
标志将阻止编译器像往常一样查看-isysroot
,因此将找不到那里的标头。您确定应该使用/usr/include
吗?如果您确实需要,那么您需要采取额外的步骤来允许找到该目录之外的标题,例如-isysroot