如何从llvm / clang(相当于gcc -MD)打印依赖项?

时间:2011-04-07 16:31:59

标签: llvm clang

我们的构建系统在编译时使用gcc生成源文件对* .d文件的标头依赖:

gcc -MD -MF foo.d -c foo.o foo.cc 

但是,我无法弄清楚如何使用llvm clang生成类似的输出。

1 个答案:

答案 0 :(得分:20)

完全一样:

clang -MD -MF foo.d -c foo.o foo.cc 

一个例子:

$ 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 \