Let say I have a simple c-library project, the layout is as follows
- src/
- square_root.c
- log.c
- power.c
- newton_method.c
- include/
- square_root.h
- log.h
- power.h
- newton_method.h
Now, I want to create a simple program(main.c) to call square_root()
# main.c
# include "square_root.h"
int main()
{
printf("%f\n", square_root(4.0));
return 0;
}
To compile the main.c, newton_method.c have to be included to the build.
gcc main.c src/square_root.c src/newton_method.c -o main
In this case, newton_method.c is a dependency of square_root.c. Finding dependencies for a source code becomes hard if the library is large or poorly written. Of course, one can include all *.c during the build, but it will make the build process slow and clumsy.
I tried
gcc -H -MM -M main.c
but it gave me only the *.h not *.c
Are there any tools for finding the dependencies of a source code ?