Demonstration - Source files
The output of gcc -MM
is demonstrated with the following three trivial compilation units and corresponding header files:
main.c:
#include "hello-world.h"
int main() {
hello_world();
}
hello-world.c:
#include "hello-world.h"
void hello_world() {
print_line("Hello world");
}
hello-world.h:
#ifndef HELLO_WORLD
#define HELLO_WORLD
#include "print-line.h"
void hello_world();
#endif
print-line.c:
#include "print-line.h"
void print_line(const char* line) {
printf("%s\n", line);
}
print-line.h:
#ifndef PRINT_LINE_H
#define PRINT_LINE_H
#include <stdio.h>
void print_line(const char* line);
#endif
Demonstration - output
gcc -MM main.c
prints
main.o: main.c hello-world.h print-line.h
gcc -MM hello-world.c
prints
hello-world.o: hello-world.c hello-world.h print-line.h
gcc -MM print-line.c
prints
print-line.o: print-line.c print-line.h