Our build system is using gcc to generate source file's header dependencies to *.d files, when compiling:
gcc -MD -MF foo.d -c foo.o foo.cc
However, I can't fi开发者_JAVA百科gure out how to produce similar output with llvm clang.
It's exactly the same:
clang -MD -MF foo.d -c foo.o foo.cc
An example:
$ cat example.c
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello, world!\n");
return 0;
}
$ clang -MD -MF example-clang.d -c -o example-clang.o example.c
$ gcc -MD -MF example-gcc.d -c -o example-gcc.o example.c
$ cat example-clang.d
example-clang.o: example.c /usr/include/stdio.h /usr/include/_types.h \
/usr/include/sys/_types.h /usr/include/sys/cdefs.h \
/usr/include/machine/_types.h /usr/include/i386/_types.h \
/usr/include/secure/_stdio.h /usr/include/secure/_common.h
$ cat example-gcc.d
example-gcc.o: example.c /usr/include/stdio.h /usr/include/_types.h \
/usr/include/sys/_types.h /usr/include/sys/cdefs.h \
/usr/include/machine/_types.h /usr/include/i386/_types.h \
/usr/include/secure/_stdio.h /usr/include/secure/_common.h
$ diff example-clang.d example-gcc.d
1c1
< example-clang.o: example.c /usr/include/stdio.h /usr/include/_types.h \
---
> example-gcc.o: example.c /usr/include/stdio.h /usr/include/_types.h \
精彩评论