首页 > 解决方案 > 如何找到源代码的依赖关系?

问题描述

假设我有一个简单的c库项目,布局如下

- src/
      - square_root.c
      - log.c
      - power.c
      - newton_method.c
- include/
      - square_root.h
      - log.h
      - power.h
      - newton_method.h

现在,我想创建一个简单的程序(main.c)来调用 square_root()

# main.c
# include "square_root.h" 
int main()
{
  printf("%f\n", square_root(4.0));
  return 0;
}

要编译 main.c,必须将 newton_method.c 包含在构建中。

gcc main.c src/square_root.c src/newton_method.c -o main

在这种情况下,newton_method.c 是 square_root.c 的依赖项。如果库很大或编写不佳,则很难找到源代码的依赖项。当然,可以在构建过程中包含所有 *.c,但这会使构建过程变得缓慢和笨拙。

我试过了

gcc -H -MM -M main.c

但它只给了我 *.h 而不是 *.c

是否有任何工具可以查找源代码的依赖项?

标签: cgccmakefilegnu-makegnu

解决方案


推荐阅读