Qt/Embedded编译与安装

1. 前言

本文介绍了Qt/Embedded的编译与安装的详细详细过程,包括简要介绍了Qt/Embedded的安装的前期准备——交叉编译链的安装。对Qt/Embedded的./configure 配置的常用参数进行了说明。

2. 安装环境说明与需要的软件资源

2.1 安装环境

  • PC环境:VMware中Ubuntu
    Linux version 2.6.32-33-generic (buildd@rothera) (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) ) #70-Ubuntu SMP Thu Jul 7 21:09:46 UTC 2011

  • arm开发板
    三星公司的:s3c2410 芯片

2.2 软件资源

  • arm-linux-gcc-4.4.3.tar.gz (若是直接通过apt-get获得则不需要)
  • qt-embedded-linux-opensource-src-4.4.0.tar.gz
  • tslib-1.4.tar.bz2
    【Tslib是一个开源的程序,能够为触摸屏驱动获得的采样提 供诸如滤波、去抖、校准等功能】

3. 步骤

3.1 步骤简介

  1. 安装交叉编译链
  2. 下载Qt/Embedded
  3. 解压,配置,编译,安装

3.2 具体步骤

3.2.1. 安装交叉编译链
  直接联网通过apt-get安装
sudo apt-get install gcc-arm-linux-gnueabi
  通过下载源码包安装:
  • 下载arm-linux-gcc-4.4.3.tar.gz
  • tar zxvf arm-linux-gcc-4.4.3.tar.gz解压
  • cd 进入解压之后的目录
  • find . -name ‘arm-linux-*’ 得到arm-linux-gcc 所在目录,例如: /usr/local/arm/4.4.3/bin
  • 添加环境变量:
    sudo gedit /etc/profile
    将 export PATH=/usr/local/arm/4.4.3/bin:$PATH 加在profile文件末尾,保存,退出
  • 输入 source /etc/profile 更新环境变量
  • 输入arm-linux-gcc -v 检验是否成功安装

3.2.2 下载、编译安装tslib-1.4.tar.bz2
首先对tslib作简单介绍:Tslib是一个开源的程序,能够为触摸屏驱动获得的采样提供诸如滤波、去抖、校准等功能,通常作为触摸屏驱动的适配层,为上层的应用提供了一个统一的接口。因为我自己开发的需要,需要为Qt/e 添加对触摸屏的支持,所以需要在编译qt的时候把tslib编译进去,假如你的开发不需要用到tslib,这一步可以忽略。
下载地址:
[tslib-1.4.0.tar.bz2](http://download.csdn.net/detail/kwansampson/9282473)

我把tslib-1.4.0.tar.bz2下载到/home/sprife/qt4/for_arm 目录下:

cd /home/sprife/qt4/for_arm
tar -jxvf tslib-1.4.0.tar.bz2
#cd tslib-1.4
#vi build.sh

修改该脚本文件为如下:
#/*******************脚本内容****************************/
#/bin/sh
export CC=arm-linux-gcc
./autogen.sh
echo "ac_cv_func_malloc_0_nonnull=yes" >arm-linux.cache
./configure --host=arm-linux --cache-file=arm-linux.cache
-prefix=$PWD/../tslib1.4-install
make
make install
#/*****************************************************/

退出保存后编译:
#./build.sh

这样tslib就被安装在了/home/sprife/qt4/for_arm/tslib1.4-install 目录下边。


3.2.3. 下载Qt/Embedded

在把交叉编译链安装好之后,终于可以进入正题了:安装Qt/Embedded,首先我们要上QT官网下载Qt/Embedded的源码,链接如下:
点击下载QT,QT/Embedded源码
Qt/Embedded编译与安装_第1张图片

点击选择不同的版本,然后可以看到不同平台不同版本的Qt源码:

Qt/Embedded编译与安装_第2张图片

上边是X11平台的Qt源码,今天只讲Qt/E的安装,所以往下找到Qt/E的源码:

Qt/Embedded编译与安装_第3张图片

可以看到这个网站上包括可Qt,Qt/E…多的平台多个版本的源码,本文只介绍Qt/E的安装。大家可以选择自己需要的版本,我安装的是 qt-embedded-linux-opensource-src-4.4.0.tar.gz
下载完后,cp到一个常用目录,我的是:/opt


3.2.4. 编译安装Qt/Embedded

需要把步骤3中安装的tslib的库文件复制到Qt/e的库文件中(下边命令的第4,5行):

  cd /opt
  tar -zxvf qt-embedded-linux-opensource-src-4.4.0.tar.gz 
  cd qt-embedded-linux-opensource-src-4.4.0
  cp -a /home/sprife/qt4/for_arm/tslib1.4-install/lib/*  /lib/ 
  cp -a /home/sprife/qt4/for_arm/tslib1.4-install/include/ts*  /include/
  ./configure -embedded arm -xplatform qws/linux-arm-g++ -depths 16 -little-endian -qt-mouse-linuxtp -qt-mouse-tslib -I/home/sprife/qt4/for_arm/tslib1.4-install/include -L/home/sprife/qt4/for_arm/tslib1.4-install/lib -debug-and-release -qt3support -qt-zlib -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -make libs -nomake examples -nomake demos -nomake docs -no-cups -iconv -qt-gfx-qvfb -prefix /usr/local/qte-arm

注:最后一步的.configure 这一步非常重要,每个参数都要根据自己的实际情况去配置,要了解有什么参数,可以输入 ./configure -help 查看,我在文章最后对一些常用的参数的意思做了解释,希望能对大家有帮助。

假如配置没问题的话,接下来

make
make install

make 编译的过程需要很长时间,我的用了3个多小时,大家尽可以一遍让它编译一遍做点其他的事情,譬如说像我这样,写这篇博客,(^_^)

make 过程中可能会出现一些错误,见我的【 Error:记住曾犯下的错误】栏目中的相关文章
假如没问题的话,make install完之后就安装完了,我的安装在 /usr/local/qte-arm目录下(安装的目录 在./configure 是在-prefix 参数中设置)

安装完之后,切换到安装目录:

 cd /usr/local/qte-arm
 cd bin

这里写图片描述

接下来就是将qmake的路径添加到path,一般而言是修改/etc/profile或者~/.bashrc 文件来添加环境变量,但是因为我安装了 qt-x11, qt-embedded, qt-x86 等不同平台和版本的qt(一般至少都需要qt-x11, qt-embedded),每个版本都有qmake,直接添加环境变量会是的到时调用时很混乱,都不知道自己用的是那个qmake,所以我用了另外一个方法,通过添加指向不同版本的qmake的软链接的方式,来更方便地调用qmake:

  cd /usr/bin
  ls -l qmake*

这样是为了查看原来已经有了的qmake(假设已经有了一个之前的qmake),然后:

mv qmake qmake.bak
ln -s /usr/local/qte-arm/bin/qmake  qmake

这样以后调用qmake的时候就是调用自己上边编译出来的qt/e 版的qmake,当然一般情况之前安装的qmake或许也会用到,这样怎么办呢?我的做法是干脆直接用不同的qmake命名不同版本的qmake,到时自己调用的时候根据自己的需要调用,我的设置如下图:

Qt/Embedded编译与安装_第4张图片

图中的不同的qmake指向不同平台的Qt的qmake,譬如说我的qmake-x就是指向x11平台的qmake,qmake-ee就是上边指向上边安装的embedded版的Qt,以后要make X11平台下的程序时,就调用qmake-x11就可以了。

最后,只需要qmake -v (我的:qmake-ee -v)确认安装成功就大功告成了!!

Qt/Embedded编译与安装_第5张图片

Enjoy



附录:./configure 参数解释

常用参数:

 ./configure -embedded arm -xplatform qws/linux-arm-g++ -depths 16 -little-endian -qt-mouse-linuxtp -qt-mouse-tslib -I/home/sprife/qt4/for_arm/tslib1.4-install/include -L/home/sprife/qt4/for_arm/tslib1.4-install/lib -debug-and-release -qt3support -qt-zlib -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -make libs -nomake examples -nomake demos -nomake docs -no-cups -iconv -qt-gfx-qvfb -prefix /usr/local/qte-arm

/**************************/
-embedded  选择嵌入式平台,如:arm
-xplatform 交叉编译时的目标平台
-depths  支持的色彩深度
-little-endian  支持小段存储
-qt-mouse-linuxtp  使用什么鼠标驱动来触发触摸屏的点击事件
-qt-mouse-tslib   支持tslib触摸屏驱动
-no-kbd-xx 如果用不到键盘的话,将kbd对应的全no掉
前面是*号的表示默认参数. +号表示该功能要求被评估,评估成功后才能被接受.
-release ……….. 调试关闭.没有调试库,自己的项目只能发布,不能调试(没有调试库的缘故)
* -debug …………. 只有调试库,没有释放库,也就是说以后自己的项目只能调试
+ -debug-and-release . 编译后包含两种库。最好编译两种库

 -prefix <dir> 设置安装目录

* -shared …………动态编译.
-static ………… 静态链接库.貌似有插件不能用静态编译。
* -no-fast ……….. configure生成所有项目makefiles文件,并编译
-fast ………….. 只生成库目录及子目录下的项目的makefiles文件.
-no-stl ………… 无c++标准库支持
* -stl …………… 有标准库支持
-qt-zlib ……….. 使用zlib绑定到qt.
+ -system-zlib ……. 使用操作系统的zlib

-no-gif ………… 不编译gif文件读取支持插件
+ -qt-gif ………… 编译gif文件读取支持插件

-no-gif ………… 不编译gif文件读取支持插件
+ -qt-gif ………… 编译gif文件读取支持插件

-no-libpng ……… 不编译PNG支持插件.
-qt-libpng ……… 编译PNG支持插件.
+ -system-libpng.. 使用系统libpng库

-no-libmng ……… 不编译MNG支持插件.
-qt-libmng ……… 编译MNG支持插件.
+ -system-libmng.. 使用系统的mng库
-no-libtiff …….. 不编译tiff支持插件.
-qt-libtiff …….. 编译tiff支持插件.
+ -system-libtiff. 使用系统的libtiff库

…参数太多就不多列了,其它的看后边的英文解释吧


全部参数:

This is the Qt for Embedded Linux Open Source Edition.

Usage:  configure [-prefix ] [-prefix-install] [-bindir ] [-libdir ]
        [-docdir ] [-headerdir ] [-plugindir  ] [-datadir ]
        [-translationdir ] [-sysconfdir ] [-examplesdir ]
        [-demosdir ] [-buildkey ] [-release] [-debug]
        [-debug-and-release] [-shared] [-static] [-no-fast] [-fast] [-no-largefile]
        [-largefile] [-no-exceptions] [-exceptions] [-no-accessibility]
        [-accessibility] [-no-stl] [-stl] [-no-sql-] [-sql-]
        [-plugin-sql-] [-system-sqlite] [-no-qt3support] [-qt3support]
        [-platform] [-D ] [-I ] [-L ] [-help]
        [-qt-zlib] [-system-zlib] [-no-gif] [-qt-gif] [-no-libtiff] [-system-libtiff]
        [-no-libpng] [-qt-libpng] [-system-libpng] [-no-libmng] [-qt-libmng]
        [-system-libmng] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg] [-make ]
        [-no-make ] [-R ]  [-l ] [-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 ] [-separate-debug-info] [-armfpa]
        [-no-optimized-qmake] [-optimized-qmake] [-no-xmlpatterns] [-xmlpatterns]
        [-no-phonon] [-phonon] [-no-svg] [-svg] [-no-webkit] [-webkit]

        [additional platform specific options (see below)]


Installation options:

 These are optional, but you may specify install directories.

    -prefix  ...... This will install everything relative to 
                         (default /usr/local/Trolltech/QtEmbedded-4.4.0)

    -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.4.0, 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  ......... Executables will be installed to 
                            (default PREFIX/bin)
    -libdir  ......... Libraries will be installed to 
                            (default PREFIX/lib)
    -docdir  ......... Documentation will be installed to 
                            (default PREFIX/doc)
    -headerdir  ...... Headers will be installed to 
                            (default PREFIX/include)
    -plugindir  ...... Plugins will be installed to 
                            (default PREFIX/plugins)
    -datadir  ........ Data used by Qt programs will be installed to 
                            (default PREFIX)
    -translationdir  . Translations of Qt programs will be installed to 
                            (default PREFIX/translations)
    -sysconfdir  ..... Settings used by Qt programs will be looked for in 
                            (default PREFIX/etc/settings)
    -examplesdir  .... Examples will be installed to 
                            (default PREFIX/examples)
    -demosdir  ....... Demos will be installed to 
                            (default PREFIX/demos)

 You may use these options to turn on strict plugin loading.

    -buildkey  .... Build the Qt library and plugins using the specified
                         .  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).

 *  -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- ... Disable SQL  entirely.
    -qt-sql- ... Enable a SQL  in the QtSql library, by default
                         none are turned on.
    -plugin-sql- Enable SQL  as a plugin to be linked to
                         at run time.

                         Possible values for :
                         [  ibase mysql odbc psql sqlite sqlite2 ]

    -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-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.

    -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   Wraps all Qt library code in 'namespace  {...}'.
    -qtlibinfix   Renames all libQt*.so to libQt*.so.

    -D  ........ Add an explicit define to the preprocessor.
    -I  ........ Add an explicit include path.
    -L  ........ 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.

Additional options:

    -make  ....... Add part to the list of parts to be built at make time.
                         (libs tools examples demos docs)
    -nomake  ..... Exclude part from the list of parts to be built.

    -R  ........ Add an explicit runtime library path to the Qt
                         libraries.
    -l  ........ 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.

    -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- Do not compile in .
    -feature- .. Compile in . The available features
                          are described in src/corelib/global/qfeatures.txt

    -embedded  .... This will enable the embedded build, you must have a
                          proper license for this switch to work.
                          Example values for : 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-libfreetype.  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  ...... Comma-separated list of supported bit-per-pixel
                          depths, from: 1, 4, 8, 12, 15, 16, 18, 24, 32 and 'all'.

    -qt-decoration-