I am looking to print a list of absolute paths to a specific header file used by gcc
without compiling anything (or specifying a particular compile target, like with gcc -M
). E.g., the following would print a list of absolute paths with all matches for limits.h
found in the appropriate directories:
gcc <flag/command> limits.h
A (non-)solution that returns only working header files is to simply create a check.c
, #include
all desired header names there, and run gcc -M check.c
.
Another solution, (albeit using bash stuff) is found in this answer and here.
Related questions that didn't quite have what I want:
gcc -print-file-name=libc.a
prints absolute path in the strange formIt looks like you could use this answer and a little shell scripting to do what you want; e.g:
$ gcc -xc -E -v - < /dev/null 2>&1 |
sed -n '/#include <...>/,/End of search list/ {/#include/d; /End/d; p};' |
xargs -IPATH find PATH -name limits.h
/usr/lib/gcc/x86_64-redhat-linux/14/include/limits.h
/usr/include/c++/14/tr1/limits.h
/usr/include/linux/limits.h
/usr/include/limits.h
Or alternatively, maybe something like this:
$ echo '#include <limits.h>' | gcc -E - | grep '/limits.h' | cut -f2 -d'"' | sort -u
/usr/include/limits.h
/usr/include/linux/limits.h
/usr/lib/gcc/x86_64-redhat-linux/14/include/limits.h