There have been a number of times when I wanted to find out where an include file was in the default compiler search path and there have been other times when I wanted to find out which header file contained a specific setting so I created this simple little bash script that does both in the hopes that it will be useful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#!/bin/bash # # This tool allows you to search for header files in the compiler # search path using the find syntax. # # % find-header.sh -name unistd.h # % find-header.sh -name syscall.h # # You can also search the contents of headers. # # % find-header.sh -name '*.h' -exec grep -n __NR_ {} \; -print # % find-header.sh -iname '*.h' -exec grep -l __NR_ {} \; # # If you just want to see the include paths: # # % find-header.sh # # Collect the arguments. N=$# ARGS=() while (( $# > 0 )) ; do ARGS=( "${ARGS[@]}" "$1" ) shift done # Get the compiler paths for gcc and g++. $(g++ -print-prog-name=cc1plus) -v > /tmp/$$.txt 2>&1 <<EOF EOF $(gcc -print-prog-name=cc1plus) -v >> /tmp/$$.txt 2>&1 <<EOF EOF INCS=$(sort -fu /tmp/$$.txt | egrep '^[ ]+/' | uniq) rm -f /tmp/$$.txt # Search the include paths. for INC in ${INCS[@]} ; do if (( $N == 0 )) ; then echo $INC else #echo find $INC -type f ${ARGS[@]} find $INC -type f ${ARGS[@]} fi done |
Hi dude! Great blog! I really enjoyed reading it.
Hello! Just want to say thank you for this interesting article! =) Peace, Joy.