Skip to content

Instantly share code, notes, and snippets.

@ldx
Created February 7, 2014 13:41
Show Gist options
  • Save ldx/8862808 to your computer and use it in GitHub Desktop.
Save ldx/8862808 to your computer and use it in GitHub Desktop.
Find library via checking gcc/ld search directories
find_lib() {
_lib="$1"
_sysroot="$(gcc -print-sysroot)"
_gcc_searchdirs=$(gcc -print-search-dirs|grep '^libraries'|sed -e 's/^libraries: //g' -e 's/:/ /g' -e "s/=/\$sysroot/g")
_ld_searchdirs=$(ld --verbose|grep SEARCH_DIR|sed -e 's/SEARCH_DIR("//g' -e 's/");//g' -e "s/=/\$sysroot/g")
for d in $_gcc_searchdirs $_ld_searchdirs; do
if [ -f "$d/$_lib" ]; then
echo -n "$d/$_lib"
return
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment