如何列出包含头文件的所有文件

Ama*_*ain 5 c header-files

标准 cscope 搜索“查找文件 #include this file”

仅返回 foo.h 直接包含在 bar.c 中的匹配项

但我对所有直接或间接的文件感兴趣

(例如,包含包含 foo.h 的头文件) include foo.h

Fre*_*Foo 4

如果您使用的是 GCC,请cpp -H在所有模块和grep您想要的标头上运行:

header=foo.h

# *.c or all interesting modules
for i in *.c; do
    # there's bound to be a cleaner regex for this
    cpp -H "$i" 2>&1 >/dev/null | grep -q "^\.* .*/$header" && echo "$i"
done
Run Code Online (Sandbox Code Playgroud)