{"id":19,"date":"2011-11-30T00:45:36","date_gmt":"2011-11-30T00:45:36","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=19"},"modified":"2011-11-30T17:49:00","modified_gmt":"2011-11-30T17:49:00","slug":"find-gccg-header-files-andor-contents","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=19","title":{"rendered":"Find gcc\/g++ header files and\/or contents"},"content":{"rendered":"<p>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.<\/p>\n<pre lang=\"Bash\">#!\/bin\/bash\r\n\r\n#\r\n# This tool allows you to search for header files in the compiler\r\n# search path using the find syntax.\r\n#\r\n#    % find-header.sh -name unistd.h\r\n#    % find-header.sh -name syscall.h\r\n#\r\n# You can also search the contents of headers.\r\n#\r\n#\u00a0\u00a0\u00a0 % find-header.sh -name '*.h' -exec grep -n __NR_ {} \\; -print\r\n#\u00a0\u00a0\u00a0 % find-header.sh -iname '*.h' -exec grep -l __NR_ {} \\;\r\n#\r\n# If you just want to see the include paths:\r\n#\r\n#\u00a0\u00a0\u00a0 % find-header.sh\r\n#\r\n\r\n# Collect the arguments.\r\nN=$#\r\nARGS=()\r\nwhile (( $# > 0 )) ; do\r\n    ARGS=( \"${ARGS[@]}\" \"$1\" )\r\n    shift\r\ndone\r\n\r\n# Get the compiler paths for gcc and g++.\r\n$(g++ -print-prog-name=cc1plus) -v > \/tmp\/$$.txt 2>&1 <<EOF\r\n\r\nEOF\r\n$(gcc -print-prog-name=cc1plus) -v >> \/tmp\/$$.txt 2>&1 <<EOF\r\n\r\nEOF\r\nINCS=$(sort -fu \/tmp\/$$.txt | egrep '^[ ]+\/' | uniq)\r\nrm -f \/tmp\/$$.txt\r\n\r\n# Search the include paths.\r\nfor INC in ${INCS[@]} ; do\r\n    if (( $N == 0 )) ; then\r\n\techo $INC\r\n    else\r\n\t#echo find $INC -type f ${ARGS[@]}\r\n\tfind $INC -type f ${ARGS[@]}\r\n    fi\r\ndone\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/joelinoff.com\/blog\/?p=19\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Find gcc\/g++ header files and\/or contents<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/19"}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19"}],"version-history":[{"count":8,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}