标准的cscope搜索“查找文件#包括此文件”如何列出包含头文件中的所有文件
回报,其中foo.h中直接在bar.c包含
但我只是那些比赛有兴趣在所有这些文件直接或间接
(例如,包括包括了foo.h头文件)包括了foo.h
标准的cscope搜索“查找文件#包括此文件”如何列出包含头文件中的所有文件
回报,其中foo.h中直接在bar.c包含
但我只是那些比赛有兴趣在所有这些文件直接或间接
(例如,包括包括了foo.h头文件)包括了foo.h
如果你使用的GCC,运行cpp -H
上所有模块和grep
为头你w蚂蚁:
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
这SO后可能会帮助你:
make include directive and dependency generation with -MM
基本上,使可生成项目中的所有依赖关系的列表。我在我的所有make文件中使用以下内容:
# Generate dependencies for all files in project
%.d: $(program_SRCS)
@ $(CC) $(CPPFLAGS) -MM $*.c | sed -e '[email protected]^\(.*\)\.o:@\1.d \1.o:@' > [email protected]
clean_list += ${program_SRCS:.c=.d}
# At the end of the makefile
# Include the list of dependancies generated for each object file
# unless make was called with target clean
ifneq "$(MAKECMDGOALS)" "clean"
-include ${program_SRCS:.c=.d}
endif
这是一个例子。假设您有foo.cpp,其中包含foo.h,其中包含bar.h,其中包含baz.h.以上将生成文件foo.d并将其包含在make文件中。该扶养文件foo.d应该是这样的:
foo.d foo.o: foo.cpp foo.h bar.h baz.h
这种方式既能使你可以看到完整的构建连锁扶养针对任何特定的目标文件。
然后找到包含特定标题的所有文件,只需要grep -l foo.h *.d
即可找出哪些源文件包含foo.h.
+1谢谢,救护员在一个巨大的#include树项目中诊断问题 – Bogatyr 2012-03-27 13:08:51