Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print dependencies from llvm / clang (equivalent of gcc -MD)?

Tags:

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 figure out how to produce similar output with llvm clang.

like image 222
Teemu Kurppa Avatar asked Apr 07 '11 16:04

Teemu Kurppa


People also ask

Is LLVM compatible with GCC?

LLVM can accept the IR from the GNU Compiler Collection (GCC) toolchain, allowing it to be used with a wide array of existing compiler front-ends written for that project.

Is Clang and GCC same?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

Is LLVM and Clang the same?

Clang is an "LLVM native" C/C++/Objective-C compiler, which aims to deliver amazingly fast compiles, extremely useful error and warning messages and to provide a platform for building great source level tools.

Does LLVM use Clang?

Clang operates in tandem with the LLVM compiler back end and has been a subproject of LLVM 2.6 and later. As with LLVM, it is free and open-source software under the Apache License 2.0 software license. Its contributors include Apple, Microsoft, Google, ARM, Sony, Intel, and AMD.


1 Answers

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 \
like image 174
Carl Norum Avatar answered Sep 19 '22 08:09

Carl Norum