我在C中编译了一个庞大的项目,但我认为有很多文件没有被使用。有什么办法,我可以得到一个在编译过程中使用/访问的文件列表。
答案 0 :(得分:2)
这取决于编译器。使用GCC,您可以使用-H
获取包含的所有文件的列表。例如,我有一个文件itobase.c
,它在指定-DTEST
时编译为程序。
来源包含:
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include "stderr.h"
…code…
#include <stdio.h>
#include <stdlib.h>
…test code…
使用-H
选项生成gcc
:
$ gcc -I. -H -DHAVE_CONFIG_H -DJLSS_STDERR -O2 -fPIC -g -std=c99 -pedantic -Wall \
> -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Werror \
> -DTEST -o itobase itobase.c /Users/jleffler/lib/64/libjl.a
. /usr/include/assert.h
.. /usr/include/sys/cdefs.h
... /usr/include/sys/_symbol_aliasing.h
... /usr/include/sys/_posix_availability.h
. /usr/include/string.h
.. /usr/include/_types.h
... /usr/include/sys/_types.h
.... /usr/include/machine/_types.h
..... /usr/include/i386/_types.h
.. /usr/include/Availability.h
... /usr/include/AvailabilityInternal.h
.. /usr/include/sys/_types/_size_t.h
.. /usr/include/sys/_types/_null.h
.. /usr/include/sys/_types/_ssize_t.h
.. /usr/include/strings.h
... /usr/include/string.h
.. /usr/include/secure/_string.h
... /usr/include/secure/_common.h
. /usr/include/unistd.h
.. /usr/include/sys/unistd.h
... /usr/include/sys/_types/_posix_vdisable.h
... /usr/include/sys/_types/_seek_set.h
.. /usr/include/sys/_types/_gid_t.h
.. /usr/include/sys/_types/_intptr_t.h
.. /usr/include/sys/_types/_off_t.h
.. /usr/include/sys/_types/_pid_t.h
.. /usr/include/sys/_types/_uid_t.h
.. /usr/include/sys/_types/_useconds_t.h
.. /usr/include/sys/select.h
... /usr/include/sys/appleapiopts.h
... /usr/include/sys/_types/_fd_def.h
... /usr/include/sys/_types/_timespec.h
... /usr/include/sys/_types/_timeval.h
... /usr/include/sys/_types/_time_t.h
... /usr/include/sys/_types/_suseconds_t.h
... /usr/include/sys/_types/_sigset_t.h
... /usr/include/sys/_types/_fd_setsize.h
... /usr/include/sys/_types/_fd_set.h
... /usr/include/sys/_types/_fd_clr.h
... /usr/include/sys/_types/_fd_isset.h
... /usr/include/sys/_types/_fd_zero.h
... /usr/include/sys/_types/_fd_copy.h
... /usr/include/sys/_select.h
.. /usr/include/sys/_types/_dev_t.h
.. /usr/include/sys/_types/_mode_t.h
.. /usr/include/sys/_types/_uuid_t.h
.. /usr/include/gethostuuid.h
. /usr/include/inttypes.h
.. /usr/include/sys/_types/_wchar_t.h
.. /usr/gcc/v4.8.2/lib/gcc/x86_64-apple-darwin12.5.0/4.8.2/include/stdint.h
... /usr/gcc/v4.8.2/lib/gcc/x86_64-apple-darwin12.5.0/4.8.2/include-fixed/stdint.h
. stderr.h
.. config.h
.. /usr/include/stdio.h
... /usr/include/sys/_types/_va_list.h
... /usr/include/secure/_stdio.h
.. /usr/gcc/v4.8.2/lib/gcc/x86_64-apple-darwin12.5.0/4.8.2/include/stdarg.h
. /usr/include/stdlib.h
.. /usr/include/sys/wait.h
... /usr/include/sys/_types/_id_t.h
... /usr/include/sys/signal.h
.... /usr/include/machine/signal.h
..... /usr/include/i386/signal.h
.... /usr/include/machine/_mcontext.h
..... /usr/include/i386/_mcontext.h
...... /usr/include/mach/i386/_structs.h
.... /usr/include/sys/_types/_sigaltstack.h
.... /usr/include/sys/_types/_ucontext.h
.... /usr/include/sys/_types/_pthread_attr_t.h
... /usr/include/sys/resource.h
... /usr/include/machine/endian.h
.... /usr/include/i386/endian.h
..... /usr/include/sys/_endian.h
...... /usr/include/libkern/_OSByteOrder.h
....... /usr/include/libkern/i386/_OSByteOrder.h
.. /usr/include/alloca.h
.. /usr/include/sys/_types/_ct_rune_t.h
.. /usr/include/sys/_types/_rune_t.h
.. /usr/include/sys/_types/_wchar_t.h
.. /usr/include/machine/types.h
... /usr/include/i386/types.h
.... /usr/include/sys/_types/_int8_t.h
.... /usr/include/sys/_types/_int16_t.h
.... /usr/include/sys/_types/_int32_t.h
.... /usr/include/sys/_types/_int64_t.h
.... /usr/include/sys/_types/_uintptr_t.h
.... /usr/include/sys/_types/___offsetof.h
Multiple include guards may be useful for:
/usr/include/assert.h
/usr/include/machine/_mcontext.h
/usr/include/secure/_stdio.h
/usr/include/secure/_string.h
/usr/include/sys/_posix_availability.h
/usr/include/sys/_symbol_aliasing.h
config.h
$
以单点开头的名称是直接包含在源中的名称。其余部分间接包含在直接包含的文件中。
在Mac OS X 10.9.2上使用GCC 4.8.2进行编译。
答案 1 :(得分:1)
C不提供你想要的东西。
所以总的来说,我没有看到可行的方法。您必须非常小心,不要删除配置中未使用但可能是其他人/用例所需的文件。