Qt编译时出现GTK theme support ......no 解决方案

解决方案: 安装 libpng{}-dev的库

  • sudo apt-get install libpng-dev
  • sudo apt-get install libpng12-dev
  • sudo apt-get install libpng16-dev

上面三条视系统中的依赖版本,ubuntu16.04下使用的是libpng12

  • 一般libxxx库中安装的是.so文件
  • 而libxxx-dev库中安装的一般是开发用到的.a 和 .h头文件还有.pc文件等

下面是问题解决方案的分析过程,有很多问题会导致出现此模块无法编译的问题,参开下面的分析过程有助于其他小伙伴尽快定位到问题。

Qt编译过程中出现如下输出:

Debug .................. yes
Qt 3 compatibility ..... no
QtDBus module .......... yes (run-time)
QtConcurrent code ...... yes
QtGui module ........... yes
QtScript module ........ yes
QtScriptTools module ... yes
QtXmlPatterns module ... yes
Phonon module .......... no
Multimedia module ...... auto
SVG module ............. yes
WebKit module .......... yes
JavaScriptCore JIT ..... To be decided by JavaScriptCore
Declarative module ..... yes
Declarative debugging ...yes
Support for S60 ........ no
Symbian DEF files ...... no
STL support ............ yes
PCH support ............ yes
MMX/3DNOW/SSE/SSE2/SSE3. yes/yes/yes/yes/yes
SSSE3/SSE4.1/SSE4.2..... yes/yes/yes
AVX..................... yes
Graphics System ........ default
IPv6 support ........... yes
IPv6 ifname support .... yes
getaddrinfo support .... yes
getifaddrs support ..... yes
Accessibility .......... yes
NIS support ............ yes
CUPS support ........... yes
Iconv support .......... yes
Glib support ........... yes
GStreamer support ...... no
PulseAudio support ..... yes
Large File support ..... yes
GIF support ............ plugin
TIFF support ........... plugin (qt)
JPEG support ........... plugin (qt)
PNG support ............ yes (qt)
MNG support ............ plugin (qt)
zlib support ........... system
Session management ..... yes
OpenGL support ......... yes (Desktop OpenGL)
OpenVG support ......... no
NAS sound support ...... no
XShape support ......... yes
XVideo support ......... yes
XSync support .......... yes
Xinerama support ....... runtime
Xcursor support ........ runtime
Xfixes support ......... runtime
Xrandr support ......... runtime
Xrender support ........ yes
Xi support ............. runtime
MIT-SHM support ........ yes
FontConfig support ..... yes
XKB Support ............ yes
immodule support ....... yes
GTK theme support ...... no
MySQL support .......... plugin
PostgreSQL support ..... plugin
ODBC support ........... plugin
TDS support ............ plugin
SQLite support ......... plugin (qt)
OpenSSL support ........ yes (run-time)
Alsa support ........... yes
ICD support ............ no

可以看出Qt在编译前进行了一些前置检测,检测过程中有一些无法编译的模块标记为no,编译过程中则不会编译此模块。
想要查看检测过程中的报错,在.configure的参数中添加-v 参数,打印编译过程的详细信息。

  • 在检测过程中的编译报错,搜索对应的模块名即可找到。定位到error的原因,就能看出为什么此模块无法编译。一般情况下,是因为系统中缺失某些库文件导致

遗憾的是,GTK模块并不能通过此方法解决,从报错信息中无法得知为什么不能编译。

解决方案:

.configure的参数中添加-gtkstyle 强制指定必须编译GTK Themes。如果无法编译将会报错退出
这个时候出现了如下报错:

Gtk theme support cannot be enabled due to functionality tests!

很遗憾这并不是一个详细报错,终端并没有输出为什么此模块无法参与编译。
用vi打开qt文件夹下的configure,直接搜索上面那条报错,会找到如下几条语句:

    if [ "$CFG_GLIB" = "yes" -a "$CFG_QGTKSTYLE" != "no" ]; then 
        if [ -n "$PKG_CONFIG" ]; then 
            QT_CFLAGS_QGTKSTYLE=`$PKG_CONFIG --cflags gtk+-2.0 ">=" 2.10 atk 2>/dev/null`
            QT_LIBS_QGTKSTYLE=`$PKG_CONFIG --libs gobject-2.0 2>/dev/null`
        fi
        if [ -n "$QT_CFLAGS_QGTKSTYLE" ] ; then 
            CFG_QGTKSTYLE=yes
            QMakeVar set QT_CFLAGS_QGTKSTYLE "$QT_CFLAGS_QGTKSTYLE"
            QMakeVar set QT_LIBS_QGTKSTYLE "$QT_LIBS_QGTKSTYLE"
        else
            if [ "$CFG_QGTKSTYLE" = "yes" ] && [ "$CFG_CONFIGURE_EXIT_ON_ERROR" = "yes" ]; then 
                echo "Gtk theme support cannot be enabled due to functionality tests!"
                echo " Turn on verbose messaging (-v) to $0 to see the final report."
                echo " If you believe this message is in error you may use the continue"
                echo " switch (-continue) to $0 to continue."
                exit 101
            else
                CFG_QGTKSTYLE=no
            fi
        fi
    elif [ "$CFG_GLIB" = "no" ]; then 
        CFG_QGTKSTYLE=no
    fi   

可以看到QT_CFLAGS_QGTKSTYLEQT_LIBS_GTKSTYLE的构建过程将报错重定向到了/dev/null修改此脚本将2>/dev/null重定向取消。再次执行configure就可以看到无法加载GTK的原因

  • 我这里报错的原因是找不到libpng16.pc文件,这个文件包含在libpng16-dev包中,安装此包后就可以解决此问题。
原创文章 39 获赞 33 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Three_dog/article/details/100144284