这篇文章是于今年7月份时写的,当时对Qt的理解还仅仅处在非常浅薄的阶段,现在看来,很多 地方写得不是很到位,现在修改重新发布,知识也是需要温习巩固的。 经常有人会在BBS和QQ群上大喊:怎么裁剪Qt,怎么安装那么困难啊。 每当我看见时,都是非常无奈,其实Qt有套良好的配置安装机制,跟大多数linux程序一样,典型的先configure,然后make,最后 make install三部曲。而如果要裁剪参数,其实可以在configure加上对应的参数来实现,通过合理的选择,完全可以做到满足项目的开发。对于嵌入式开发来说,资源是极其重要的,这就要求我们应该对应不同的项目开发,对Qte进行不同的裁剪来实现。 其实,在前面的减少Qt编译时间暨简单Qt裁剪(cuteqt)已经对这个题目有了非常详细的概述,并且通过qconfig工具可以做到控件级的裁剪,但是如果能在configure阶段,能搞清楚参数,我想对于开发也是有很大的帮助。 为了与时俱进,本人的参数来源都是参照qt-embedded-linux-opensource-src-4.5.3,至于Qt4.6.0,已经把所有平台融化在一起,参数也是,但是鉴于现在Qt4.6.0的bug多得让人难以忍受,短时间内是不会去使用它作为开发的首选库。 当进入解压好的源码包后,使用./configure –help命令,可以获得相应帮助,里面详细地介绍了各个参数,其实无需在网上大费周折,只要好好看懂这些参数就可以熟练掌握QtEmbedded的裁减配置。 获得的帮助信息如下: Usage: configure [-h] [-prefix <dir>] [-prefix-install] [-bindir <dir>] [-libdir <dir>] [-docdir <dir>] [-headerdir <dir>] [-plugindir <dir> ] [-datadir <dir>] [-translationdir <dir>] [-sysconfdir <dir>] [-examplesdir <dir>] [-demosdir <dir>] [-buildkey <key>] [-release] [-debug] [-debug-and-release] [-developer-build] [-shared] [-static] [-no-fast] [-fast] [-no-largefile] [-largefile] [-no-exceptions] [-exceptions] [-no-accessibility] [-accessibility] [-no-stl] [-stl] [-no-sql-<driver>] [-sql-<driver>] [-plugin-sql-<driver>] [-system-sqlite] [-no-qt3support] [-qt3support] [-platform] [-D <string>] [-I <string>] [-L <string>] [-help] [-qt-zlib] [-system-zlib] [-no-gif] [-qt-gif] [-no-libtiff] [-qt-libtiff] [-system-libtiff] [-no-libpng] [-qt-libpng] [-system-libpng] [-no-libmng] [-qt-libmng] [-system-libmng] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg] [-make <part>] [-no-make <part>] [-R <string>] [-l <string>] [-no-rpath] [-rpath] [-continue] [-verbose] [-v] [-silent] [-no-nis] [-nis] [-no-cups] [-cups] [-no-iconv] [-iconv] [-no-pch] [-pch] [-no-dbus] [-dbus] [-dbus-linked] [-no-separate-debug-info] [-no-mmx] [-no-3dnow] [-no-sse] [-no-sse2] [-qtnamespace <namespace>] [-qtlibinfix <infix>] [-separate-debug-info] [-armfpa] [-no-optimized-qmake] [-optimized-qmake] [-no-xmlpatterns] [-xmlpatterns] [-no-phonon] [-phonon] [-no-phonon-backend] [-phonon-backend] [-no-openssl] [-openssl] [-openssl-linked] [-no-gtkstyle] [-gtkstyle] [-no-svg] [-svg] [-no-webkit] [-webkit] [-no-scripttools] [-scripttools] [additional platform specific options (see below)] Installation options: These are optional, but you may specify install directories. -prefix <dir> ...... This will install everything relative to <dir> (default /usr/local/Trolltech/QtEmbedded-4.5.3) -hostprefix [dir] .. Tools and libraries needed when developing applications are installed in [dir]. If [dir] is not given, the current build directory will be used. * -prefix-install .... Force a sandboxed "local" installation of Qt. This will install into /usr/local/Trolltech/QtEmbedded-4.5.3, if this option is disabled then some platforms will attempt a "system" install by placing default values to be placed in a system location other than PREFIX. You may use these to separate different parts of the install: -bindir <dir> ......... Executables will be installed to <dir> (default PREFIX/bin) -libdir <dir> ......... Libraries will be installed to <dir> (default PREFIX/lib) -docdir <dir> ......... Documentation will be installed to <dir> (default PREFIX/doc) -headerdir <dir> ...... Headers will be installed to <dir> (default PREFIX/include) -plugindir <dir> ...... Plugins will be installed to <dir> (default PREFIX/plugins) -datadir <dir> ........ Data used by Qt programs will be installed to <dir> (default PREFIX) -translationdir <dir> . Translations of Qt programs will be installed to <dir> (default PREFIX/translations) -sysconfdir <dir> ..... Settings used by Qt programs will be looked for in <dir> (default PREFIX/etc/settings) -examplesdir <dir> .... Examples will be installed to <dir> (default PREFIX/examples) -demosdir <dir> ....... Demos will be installed to <dir> (default PREFIX/demos) You may use these options to turn on strict plugin loading. -buildkey <key> .... Build the Qt library and plugins using the specified <key>. When the library loads plugins, it will only load those that have a matching key. Configure options: The defaults (*) are usually acceptable. A plus (+) denotes a default value that needs to be evaluated. If the evaluation succeeds, the feature is included. Here is a short explanation of each option: * -release ........... Compile and link Qt with debugging turned off. -debug ............. Compile and link Qt with debugging turned on. -debug-and-release . Compile and link two versions of Qt, with and without debugging turned on (Mac only). -developer-build.... Compile and link Qt with Qt developer options (including auto-tests exporting) -opensource......... Compile and link the Open-Source Edition of Qt. -commercial......... Compile and link the Commercial Edition of Qt. * -shared ............ Create and use shared Qt libraries. -static ............ Create and use static Qt libraries. * -no-fast ........... Configure Qt normally by generating Makefiles for all project files. -fast .............. Configure Qt quickly by generating Makefiles only for library and subdirectory targets. All other Makefiles are created as wrappers, which will in turn run qmake. -no-largefile ...... Disables large file support. + -largefile ......... Enables Qt to access files larger than 4 GB. * -no-exceptions ..... Disable exceptions on compilers that support it. -exceptions ........ Enable exceptions on compilers that support it. -no-accessibility .. Do not compile Accessibility support. * -accessibility ..... Compile Accessibility support. -no-stl ............ Do not compile STL support. * -stl ............... Compile STL support. -no-sql-<driver> ... Disable SQL <driver> entirely. -qt-sql-<driver> ... Enable a SQL <driver> in the QtSql library, by default none are turned on. -plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to at run time. Possible values for <driver>: [ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ] -system-sqlite ..... Use sqlite from the operating system. -no-qt3support ..... Disables the Qt 3 support functionality. * -qt3support ........ Enables the Qt 3 support functionality. -no-xmlpatterns .... Do not build the QtXmlPatterns module. + -xmlpatterns ....... Build the QtXmlPatterns module. QtXmlPatterns is built if a decent C++ compiler is used and exceptions are enabled. -no-phonon ......... Do not build the Phonon module. + -phonon ............ Build the Phonon module. Phonon is built if a decent C++ compiler is used. -no-phonon-backend.. Do not build the platform phonon plugin. + -phonon-backend..... Build the platform phonon plugin. -no-svg ............ Do not build the SVG module. + -svg ............... Build the SVG module. -no-webkit ......... Do not build the WebKit module. + -webkit ............ Build the WebKit module. WebKit is built if a decent C++ compiler is used. -no-scripttools .... Do not build the QtScriptTools module. + -scripttools ....... Build the QtScriptTools module. -platform target ... The operating system and compiler you are building on (qws/linux-x86-g++). See the README file for a list of supported operating systems and compilers. -no-mmx ............ Do not compile with use of MMX instructions. -no-3dnow .......... Do not compile with use of 3DNOW instructions. -no-sse ............ Do not compile with use of SSE instructions. -no-sse2 ........... Do not compile with use of SSE2 instructions. -qtnamespace <name> Wraps all Qt library code in 'namespace <name> {...}'. -qtlibinfix <infix> Renames all libQt*.so to libQt*<infix>.so. -D <string> ........ Add an explicit define to the preprocessor. -I <string> ........ Add an explicit include path. -L <string> ........ Add an explicit library path. -help, -h .......... Display this information. Third Party Libraries: -qt-zlib ........... Use the zlib bundled with Qt. + -system-zlib ....... Use zlib from the operating system. See http://www.gzip.org/zlib -no-gif ............ Do not compile the plugin for GIF reading support. * -qt-gif ............ Compile the plugin for GIF reading support. See also src/plugins/imageformats/gif/qgifhandler.h -no-libtiff ........ Do not compile the plugin for TIFF support. -qt-libtiff ........ Use the libtiff bundled with Qt. + -system-libtiff .... Use libtiff from the operating system. See http://www.libtiff.org -no-libpng ......... Do not compile in PNG support. -qt-libpng ......... Use the libpng bundled with Qt. + -system-libpng ..... Use libpng from the operating system. See http://www.libpng.org/pub/png -no-libmng ......... Do not compile the plugin for MNG support. -qt-libmng ......... Use the libmng bundled with Qt. + -system-libmng ..... Use libmng from the operating system. See http://www.libmng.com -no-libjpeg ........ Do not compile the plugin for JPEG support. -qt-libjpeg ........ Use the libjpeg bundled with Qt. + -system-libjpeg .... Use libjpeg from the operating system. See http://www.ijg.org -no-openssl ........ Do not compile support for OpenSSL. + -openssl ........... Enable run-time OpenSSL support. -openssl-linked .... Enabled linked OpenSSL support. -ptmalloc .......... Override the system memory allocator with ptmalloc. (Experimental.) Additional options: -make <part> ....... Add part to the list of parts to be built at make time. (libs tools examples demos docs translations) -nomake <part> ..... Exclude part from the list of parts to be built. -R <string> ........ Add an explicit runtime library path to the Qt libraries. -l <string> ........ Add an explicit library. -no-rpath .......... Do not use the library install path as a runtime library path. + -rpath ............. Link Qt libraries and executables using the library install path as a runtime library path. Equivalent to -R install_libpath -continue .......... Continue as far as possible if an error occurs. -verbose, -v ....... Print verbose information about each step of the configure process. -silent ............ Reduce the build output so that warnings and errors can be seen more easily. * -no-optimized-qmake ... Do not build qmake optimized. -optimized-qmake ...... Build qmake optimized. -no-nis ............ Do not compile NIS support. * -nis ............... Compile NIS support. -no-cups ........... Do not compile CUPS support. * -cups .............. Compile CUPS support. Requires cups/cups.h and libcups.so.2. -no-iconv .......... Do not compile support for iconv(3). * -iconv ............. Compile support for iconv(3). -no-pch ............ Do not use precompiled header support. * -pch ............... Use precompiled header support. -no-dbus ........... Do not compile the QtDBus module. + -dbus .............. Compile the QtDBus module and dynamically load libdbus-1. -dbus-linked ....... Compile the QtDBus module and link to libdbus-1. -reduce-relocations ..... Reduce relocations in the libraries through extra linker optimizations (Qt/X11 and Qt for Embedded Linux only; experimental; needs GNU ld >= 2.18). -no-separate-debug-info . Do not store debug information in a separate file. * -separate-debug-info .... Strip debug information into a separate .debug file. Qt for Embedded Linux only: -xplatform target ... The target platform when cross-compiling. -no-feature-<feature> Do not compile in <feature>. -feature-<feature> .. Compile in <feature>. The available features are described in src/corelib/global/qfeatures.txt -embedded <arch> .... This will enable the embedded build, you must have a proper license for this switch to work. Example values for <arch>: arm mips x86 generic -armfpa ............. Target platform is uses the ARM-FPA floating point format. -no-armfpa .......... Target platform does not use the ARM-FPA floating point format. The floating point format is usually autodetected by configure. Use this to override the detected value. -little-endian ...... Target platform is little endian (LSB first). -big-endian ......... Target platform is big endian (MSB first). -host-little-endian . Host platform is little endian (LSB first). -host-big-endian .... Host platform is big endian (MSB first). You only need to specify the endianness when cross-compiling, otherwise the host endianness will be used. -no-freetype ........ Do not compile in Freetype2 support. -qt-freetype ........ Use the libfreetype bundled with Qt. * -system-freetype .... Use libfreetype from the operating system. See http://www.freetype.org/ -qconfig local ...... Use src/corelib/global/qconfig-local.h rather than the default (full). -depths <list> ...... Comma-separated list of supported bit-per-pixel depths, from: 1, 4, 8, 12, 15, 16, 18, 24, 32 and 'all'. -qt-decoration-<style> ....Enable a decoration <style> in the QtGui library, by default all available decorations are on. Possible values for <style>: [ styled windows default ] -plugin-decoration-<style> Enable decoration <style> as a plugin to be linked to at run time. Possible values for <style>: [ default styled windows ] -no-decoration-<style> ....Disable decoration <style> entirely. Possible values for <style>: [ styled windows default ] -no-opengl .......... Do not support OpenGL. -opengl <api> ....... Enable OpenGL ES support With no parameter, this will attempt to auto-detect OpenGL ES 1.x or 2.x. Use es1, es1cl or es2 for <api> to override auto-detection. NOTE: A QGLScreen driver for the hardware is required to support OpenGL ES on Qt for Embedded Linux. -qt-gfx-<driver> ... Enable a graphics <driver> in the QtGui library. Possible values for <driver>: [ linuxfb transformed qvfb vnc multiscreen ] -plugin-gfx-<driver> Enable graphics <driver> as a plugin to be linked to at run time. Possible values for <driver>: [ ahi directfb hybrid linuxfb powervr qvfb transformed vnc ] -no-gfx-<driver> ... Disable graphics <driver> entirely. Possible values for <driver>: [ linuxfb transformed qvfb vnc multiscreen ] -qt-kbd-<driver> ... Enable a keyboard <driver> in the QtGui library. Possible values for <driver>: [ tty usb sl5000 yopy vr41xx qvfb ] -plugin-kbd-<driver> Enable keyboard <driver> as a plugin to be linked to at runtime. Possible values for <driver>: [ linuxis sl5000 usb vr41xx yopy ] -no-kbd-<driver> ... Disable keyboard <driver> entirely. Possible values for <driver>: [ tty usb sl5000 yopy vr41xx qvfb ] -qt-mouse-<driver> ... Enable a mouse <driver> in the QtGui library. Possible values for <driver>: [ pc bus linuxtp yopy vr41xx tslib qvfb ] -plugin-mouse-<driver> Enable mouse <driver> as a plugin to be linked to at runtime. Possible values for <driver>: [ bus linuxis linuxtp pc tslib vr41xx yopy ] -no-mouse-<driver> ... Disable mouse <driver> entirely. Possible values for <driver>: [ pc bus linuxtp yopy vr41xx tslib qvfb ] -iwmmxt ............ Compile using the iWMMXt instruction set (available on some XScale CPUs). -no-glib ........... Do not compile Glib support. + -glib .............. Compile Glib support. 这么参数,顺便一扫,会觉得头也晕了,但是其实仔细分析下,就会发现这些参数大多数是不难的,意思是非常好了解。本人移植QtEmbedded时,就是一个一个参数配置过来的,当然,有些是可以不用去理会的么,接下来,就一一对这些信息作解释。 我们可以发现,有的参数前面有*号,这就意味这如果我们什么也不做,直接配置编译的话,就会把这些参数默认进去。不过,如果什么也不做,那裁剪也无从说起了。为了便于分析,接下来,我就是以如下格式进行: 参数 解释 Usage: configure [-h] [-prefix <dir>] [-prefix-install] [-bindir <dir>] [-libdir <dir>] [-docdir <dir>] [-headerdir <dir>] [-plugindir <dir> ] [-datadir <dir>] [-translationdir <dir>] [-sysconfdir <dir>] [-examplesdir <dir>] [-demosdir <dir>] [-buildkey <key>] [-release] [-debug] [-debug-and-release] [-developer-build] [-shared] [-static] [-no-fast] [-fast] [-no-largefile] [-largefile] [-no-exceptions] [-exceptions] [-no-accessibility] [-accessibility] [-no-stl] [-stl] [-no-sql-<driver>] [-sql-<driver>] [-plugin-sql-<driver>] [-system-sqlite] [-no-qt3support] [-qt3support] [-platform] [-D <string>] [-I <string>] [-L <string>] [-help] [-qt-zlib] [-system-zlib] [-no-gif] [-qt-gif] [-no-libtiff] [-qt-libtiff] [-system-libtiff] [-no-libpng] [-qt-libpng] [-system-libpng] [-no-libmng] [-qt-libmng] [-system-libmng] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg] [-make <part>] [-no-make <part>] [-R <string>] [-l <string>] [-no-rpath] [-rpath] [-continue] [-verbose] [-v] [-silent] [-no-nis] [-nis] [-no-cups] [-cups] [-no-iconv] [-iconv] [-no-pch] [-pch] [-no-dbus] [-dbus] [-dbus-linked] [-no-separate-debug-info] [-no-mmx] [-no-3dnow] [-no-sse] [-no-sse2] [-qtnamespace <namespace>] [-qtlibinfix <infix>] [-separate-debug-info] [-armfpa] [-no-optimized-qmake] [-optimized-qmake] [-no-xmlpatterns] [-xmlpatterns] [-no-phonon] [-phonon] [-no-phonon-backend] [-phonon-backend] [-no-openssl] [-openssl] [-openssl-linked] [-no-gtkstyle] [-gtkstyle] [-no-svg] [-svg] [-no-webkit] [-webkit] [-no-scripttools] [-scripttools] [additional platform specific options (see below)] -release 首先可以看见是一堆参数列表,其实这就是配置出来的参数的基本样式,简单来说,是一个例子,但是这个例子,并不是直接可用的。同时,也是Qt通用版本的参数,在不同的平台上面,还有对照各自平台也有自己相关的参数。 Installation options: These are optional, but you may specify install directories. -prefix <dir> ...... This will install everything relative to <dir> (default /usr/local/Trolltech/QtEmbedded-4.5.3) 首先是安装参数, -prefix是Linux编译里最常见的参数之一,也就是指定安装目录,一般默认的是 安装在/usr/local/Trolltech/下,比如嵌入式就是/usr/local/Trolltech/QtEmbedded-4.5.3。 -hostprefix [dir] .. Tools and libraries needed when developing applications are installed in [dir]. If [dir] is not given, the current build directory will be used. 工具和库在安装过程中需要有一个编译目录,这个参数就是指定该目录的。 * -prefix-install .... Force a sandboxed "local" installation of Qt. This will install into /usr/local/Trolltech/QtEmbedded-4.5.3, if this option is disabled then some platforms will attempt a "system" install by placing default values to be placed in a system location other than PREFIX. 指定沙盒安装目录,如果选用了这个选项,安装目录就会强制安装到 /usr/local/Trolltech/下,如果参数没有选择,那在部分平台上会使用系统安装来替代掉原有默认的文件。 You may use these to separate different parts of the install: -bindir <dir> ......... Executables will be installed to <dir> (default PREFIX/bin) -libdir <dir> ......... Libraries will be installed to <dir> (default PREFIX/lib) -docdir <dir> ......... Documentation will be installed to <dir> (default PREFIX/doc) -headerdir <dir> ...... Headers will be installed to <dir> (default PREFIX/include) -plugindir <dir> ...... Plugins will be installed to <dir> (default PREFIX/plugins) -datadir <dir> ........ Data used by Qt programs will be installed to <dir> (default PREFIX) -translationdir <dir> . Translations of Qt programs will be installed to <dir> (default PREFIX/translations) -sysconfdir <dir> ..... Settings used by Qt programs will be looked for in <dir> (default PREFIX/etc/settings) -examplesdir <dir> .... Examples will be installed to <dir> (default PREFIX/examples) -demosdir <dir> ....... Demos will be installed to <dir> (default PREFIX/demos) 这些参数是用来分别对Qt的各自模块指定安装目录,通常情况下,是不会是配置的。 You may use these options to turn on strict plugin loading. -buildkey <key> .... Build the Qt library and plugins using the specified <key>. When the library loads plugins, it will only load those that have a matching key. 该参数是用来严格使用插件的载入,使用<key>来描述插件,当被载入时,只有拥有 matching key的才能载入插件。 Configure options: 下面开始就是配置参数 -release 这个参数显而易见,就是编译Qt库以发布版的模式进行,一般来说,最后系统完成后,库就应该是发布版。 -debug 与上面对应,自然是调试版了,如果开发的话,可以选择它吧,最后生成调试版的库文件。 -debug-and-release 上面那两个的儿子,既生成发布版的库,也生成调试版的库。 -developer-build 给开发者也可以用这个的,选了这个后,可以进行自动测试,不过还没去用过,以后可以研究研究。 -opensource -commercial 这两个参数是指是编译是商业版本的,还是开源版本呢,视个人情况而定。 -shared -static 这两个参数是指Qt的lib以动态还是静态编译生成,这自然也是视个人需要的。 -no-fast -fast 这两个就很有关系,如果对自己的电脑性能很有信心,那就选第一个,那所有的工程文件都会生成到makefiles中,那编译的时间,估计可以看完变形金刚了。如果选第二个,那就加入子目录和库到makefiles,这样就能加快编译的速度。 -no-largefile -largefile 顾名思义,支不支持大文件,一般来说,嵌入式里是不会有从超过4G的大文件的,那就选第一个吧。 -no-exceptions -exceptions 计算机英语够好的人都该懂,这个自然就是异常情况,选则编译器支持抛出异常,否则不支持。 -no-accessibility -accessibility 可访问性的支持,说实话,这个我真不知道有什么有用了。等哪天发现了,再来好好解释。 -no-stl -stl 是都加入stl的支持,标准模板库,这应该算是C++程序员应该都了解了,再不济,那也总听说过大名吧。 no-sql-<driver> -qt-sql-<driver> -plugin-sql-<driver> 这个可要好好说明下,一般来说,对于一个优秀的项目开发,数据库是必不可少的,qt也自带了大多数数据库驱动,可以完美地支持数据库的使用。对于数据库的使用,我们可以直接qt驱动编译进去,或者以插件的形式编译进去。一般来说,最简单地就是直接编译进去,但使用插件形式的可以更加灵活,针对不同的需求将驱动插件添加。其中,<>代表的是驱动名,如果我想直接添加sqlite的支持话,形式如下:-qt-sql-sqlite。其他名称可以自己查看参数里,有详细地介绍。 -system-sqlite sqlite真受欢迎啊,当然那么优秀的嵌入式数据库,本人也是基本使用它来进行开发。这个参数意思是使用操作系统上的sqlite数据库,如果是不太会移植的,可以考虑直接使用qt自带的驱动。 -no-qt3support -qt3support 这个也是简洁易懂,加不加对qt3的支持。 no-xmlpatterns -xmlpatterns 选择对xml的支持,如果对网络无需求的话,就不用加了。 -no-phonon -phonon phonon是qt中处理多媒体的模块,比如放放视频什么来着,不过本人从没用过,也是根据需要选择的。 -no-phonon-backend -phonon-backend 与上面类似,只不过这两是以插件的形式加入支持。 -no-svg -svg 是否加入svg的支持,svg即可缩放矢量图形。 -no-webkit -webkit 是否加入webkit的支持,这可是个好东西,不过如果跟网络不搭界的话,还是不支持吧。 -no-scripttools -scripttools 是否加入脚本工具的支持,这对php等脚本工程师来说是个很棒的参数,但对于我这样菜鸟,就别提了。 -platform target 目标平台,这可是关键了,如果不注意的话,编译出来是x86上的话,哪怕是再牛的嵌入式工程师来也没法帮你移植到开发板上。通常,本人是linux-arm-g++。 -no-mmx -no-3dnow -no-sse -no-sse2 这四个参数是针对CPU的指令集,老实说,我也不甚了解,不过,对于开发并不是影响很大。 -qtnamespace 把qt的库封装到命名空间,没啥重要用处,依个人爱好加吧。 -qtlibinfix 将所有的qt的.so库重命名,也没啥大用处。 好了,以上就是qt最基本的参数,接下来静待下篇吧。
关键字: Qt,embedded
