hi guys
It's about the beginning section of every code where you give the libraries
I need a shortcut to find some file given through #include<file.name> without searching though all header data.
is there any way?
Thanks
Printable View
hi guys
It's about the beginning section of every code where you give the libraries
I need a shortcut to find some file given through #include<file.name> without searching though all header data.
is there any way?
Thanks
Your question is ambiguous.
In code within an #include'd file, it is possible to find its filename (or, more accurately, a string that is representative of the filename) using the __FILE__ prefined macro (which is specified in the standard).
From a source file that is #include'ing another files, each #include directive specifies the name of the file it is including. There is no way, within a source file, to write code to enumerate the files which that source file has #include'd.
The only way is to use some other program (eg a program that searches files for a string) to externally search the source files for #include directives. Even that can be fooled, however, by conditional macro expansion (eg an #include directive surrounded by #ifdef ABC/#endif where ABC is not defined) or by the fact that the filename given to an #include directive can be the result of a macro expansion.
I suspect your requirement is flawed (i.e. you're actually trying to do something else, and have somehow latched onto the idea of doing this in error).
Well you could do this
Or thisCode:$ gcc -M foo.c
foo.o: foo.c /usr/include/stdio.h /usr/include/features.h \
/usr/include/x86_64-linux-gnu/bits/predefs.h \
/usr/include/x86_64-linux-gnu/sys/cdefs.h \
/usr/include/x86_64-linux-gnu/bits/wordsize.h \
/usr/include/x86_64-linux-gnu/gnu/stubs.h \
/usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include/stddef.h \
/usr/include/x86_64-linux-gnu/bits/types.h \
/usr/include/x86_64-linux-gnu/bits/typesizes.h /usr/include/libio.h \
/usr/include/_G_config.h /usr/include/wchar.h \
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include/stdarg.h \
/usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
/usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed/limits.h \
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed/syslimits.h \
/usr/include/limits.h /usr/include/x86_64-linux-gnu/bits/posix1_lim.h \
/usr/include/x86_64-linux-gnu/bits/local_lim.h \
/usr/include/linux/limits.h \
/usr/include/x86_64-linux-gnu/bits/posix2_lim.h
What's the chance that you're using some other compiler, but didn't think it was worth mentioning at the time.Code:$ gcc -E foo.c | awk '/^#/ && $3 ~ "/" { print $3 }' | sort -u
"/usr/include/features.h"
"/usr/include/_G_config.h"
"/usr/include/libio.h"
"/usr/include/limits.h"
"/usr/include/linux/limits.h"
"/usr/include/stdio.h"
"/usr/include/wchar.h"
"/usr/include/x86_64-linux-gnu/bits/local_lim.h"
"/usr/include/x86_64-linux-gnu/bits/posix1_lim.h"
"/usr/include/x86_64-linux-gnu/bits/posix2_lim.h"
"/usr/include/x86_64-linux-gnu/bits/predefs.h"
"/usr/include/x86_64-linux-gnu/bits/stdio_lim.h"
"/usr/include/x86_64-linux-gnu/bits/sys_errlist.h"
"/usr/include/x86_64-linux-gnu/bits/types.h"
"/usr/include/x86_64-linux-gnu/bits/typesizes.h"
"/usr/include/x86_64-linux-gnu/bits/wordsize.h"
"/usr/include/x86_64-linux-gnu/gnu/stubs-64.h"
"/usr/include/x86_64-linux-gnu/gnu/stubs.h"
"/usr/include/x86_64-linux-gnu/sys/cdefs.h"
"/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed/limits.h"
"/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed/syslimits.h"
"/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include/stdarg.h"
"/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include/stddef.h"