Search code examples
bashgtk3

Detect availability of GTK3 in shell script


We want to avoid the user to make changes to our application start script of only GTK2 is available, but not GTK3. What is the preferred way to detect the availability of GTK3?


Solution

  • For Linux and regardless of if it's based on rpm or deb, a generic form of getting gtk library versions could be

    find /usr/lib64/ -name 'libgtk*' | xargs readelf -d |\
    gawk 'BEGIN{ FS="[[]|[]]"}{if($0 ~ /SONAME/){ print $2 }}' | sort | uniq
    

    Result:

    libgtk-3.so.0
    libgtk-x11-2.0.so.0
    

    With that, it's possible to get available GTK versions.