本博客为本人学生时代的技术博客,工作后10年已经不再更新,需要关注可以访问geekpm.com,点击访问!

Linux 下编译、安装、配置 QT

打算做嵌入式图像处理,计划方案嵌入式Linux+OpenCV+QT,昨天简单入门OpenCV今天看看QT,QT就先弄Linux下面的,回家之前争取把基本的摸通,然后能在板子上跑起来。

软件环境


Linux:Ubuntu 12.04 X86

QT:4.8.4

关于QT安装


QT的早期版本和现在版本有点变化,提供的文件也不尽相同,最新的版本为5.0,我这里用的是4.8.4,一个完整的QT应该包括QT库、IDE也就是QT creator,在Linux下的安装中,目前看到的主要有三种方法:

1、.bin文件直接安装,文件名为qt-sdk-……,一个./bin直接包括了所有相关工具,安装起来最为简单方便,但是目前的4.8.4在几个网站上已经找不到总的sdk的bin文件了,老版本的还是可以的。

2、Ubuntu下使用atp-get安装,方法如下(未验证)

sudo apt-get install qt4-dev-tools #开发包   
sudo apt-get install qtcreator #IDE  
sudo apt-get install qt4-doc #开发帮助文档   
sudo apt-get install qt4-qtconfig #配置工具   
sudo apt-get install qt4-demos #DEMO源码  QT

3、这就是本文用的方法,就是下载源码包,自己编译安装,最为麻烦,但是本来就是学习的,况且现在只能下载到源码包,那就先学习这种方法把。

软件下载


QT有好几个下载网站,这里汇总介绍,自从诺基亚公司放弃Meego、遣散Qt开发团队以后,Qt商业版本的网站移到了qt.digia.com,而开源版本则放到了qt-project.org  :

1、首先是诺基亚的官方网站http://qt.digia.com/  这个是不太方便的,想快速下载的接着看后面的。

此网站需要填写用户名和邮箱地址,下载地址会发送到邮件里,我就把我收到的地址贴出来吧。下面是邮件中的地址汇总。这里面的linux源码是commercial版本。

Qt 4.8.4 for embedded Linux

http://dist.qt.digia.com/developer/download/qt-everywhere-commercial-src-4.8.4.tar.gz

Installing Qt for embedded Linux

http://qt-project.org/doc/qt-4.8/qt-embedded-install.html

Qt Commercial Charts 1.1.0

http://dist.qt.digia.com/developer/download_charts/qt-commercial-charts-src-1.1.0.tar.gz

Qt 5.0.0 Sources

http://dist.qt.digia.com/developer/download_50/qt-everywhere-commercial-src-5.0.0.tar.gz

Qt 4.8.4 for Windows (Src and VS2008 32bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-vs2008.exe

Qt Visual Studio Addin 1.1.11 for Qt4 (Binary)

http://dist.qt.digia.com/developer/download/qt-vs-addin-1.1.11.exe

Qt 4.8.4 for Windows (Src and VS2010 32bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-vs2010.exe

Qt 4.8.4 for Windows (Src and MinGW 32bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-mingw.exe

Qt Creator 2.6.1 for Windows (32bit Binary)

http://dist.qt.digia.com/developer/download_creator/qt-creator-win-commercial-2.6.1.exe

Qt 4.8.4 for Windows (Src and VS2010 64bit Binary)

http://dist.qt.digia.com/developer/download/qt-win-commercial-4.8.4-vs2010-64bit.exe

Qt Commercial Charts 1.1.0

http://dist.qt.digia.com/developer/download_charts/qt-commercial-charts-src-1.1.0.zip

Qt 5.0.0 Sources

http://dist.qt.digia.com/developer/download_50/qt-everywhere-commercial-src-5.0.0.zip

Qt 5.0.0 Offline SDK for Windows (32-bit Binary)

http://dist.qt.digia.com/developer/download_50/qt-windows-commercial-5.0.0-msvc2010_32-x86-offline.exe

Qt Visual Studio Addin 1.2.0 for Qt5 (Binary)

http://dist.qt.digia.com/developer/download_50/qt-vs-addin-1.2.0.exe

2、QT-project网站下载 http://qt-project.org/downloads

这个网站就直接而且清晰多了,分类很清楚,如下图所示。

image

需要说明的是Qt libraries 4.8.4 for embedded Linux (236 MB) 下载链接和Qt libraries 4.8.4 for Linux/X11 (225 MB) 其实下载的是一个东西,反正我看到的链接地址都是一样的,这也就是Linux下我们需要用的。另外从这个页面再下载开发所用的IDE QT Creator,这是一个bin文件,可以直接安装。

QT的编译与安装


1、拷贝文件到自己想要的文件夹,解压:

tar zxvf qt-everywhere-opensource-src-4.8.4.tar.gz

2、进入解压后文件目录,执行配置

root@emouse:~/study# cd qt-everywhere-opensource-src-4.8.4/

root@emouse:~/study/qt-everywhere-opensource-src-4.8.4# ./configure

此处也可以加上配置前缀./configure -prefix /opt/qt-4.8.4-x11

这样的话再后面编译过程中的文件会复制到/opt/qt-4.8.4-x11 这个目录下(目录不存在会自动创建),好处是源码便于管理,

关于这部分前缀配置可以我在config文件中找到这部分代码,可以参考,可以从这段代码中看出相应的配置以及没有配置的情况下默认安装目录,代码位于3594行,如下:

#-------------------------------------------------------------------------------
# post process QT_INSTALL_* variables
#-------------------------------------------------------------------------------

#prefix
if [ -z "$QT_INSTALL_PREFIX" ]; then
    if [ "$CFG_DEV" = "yes" ]; then
        QT_INSTALL_PREFIX="$outpath" # In Development, we use sandboxed builds by default
    elif [ "$PLATFORM_QWS" = "yes" -o "$PLATFORM_QPA" = "yes" ]; then
        if [ "$PLATFORM_QPA" = "yes" ]; then
    QT_INSTALL_PREFIX="/usr/local/Trolltech/QtLighthouse-${QT_VERSION}"
        else
    QT_INSTALL_PREFIX="/usr/local/Trolltech/QtEmbedded-${QT_VERSION}"
        fi
        if [ "$PLATFORM" != "$XPLATFORM" ]; then
            QT_INSTALL_PREFIX="${QT_INSTALL_PREFIX}-${CFG_ARCH}"
        fi
    elif [ -d "$EPOCROOT" ] && [ "$XPLATFORM_SYMBIAN" = "yes" ]; then
        if [ "$XPLATFORM_SYMBIAN" = "yes" ]; then
            QT_INSTALL_PREFIX="$EPOCROOT/epoc32/"
            QT_INSTALL_LIBS="$EPOCROOT/epoc32/release/armv5/lib/"
        fi
    else
        QT_INSTALL_PREFIX="/usr/local/Trolltech/Qt-${QT_VERSION}" # the default install prefix is /usr/local/Trolltech/Qt-$QT_VERSION

配置过程中会有以下提示:

Which edition of Qt do you want to use ?

Type 'c' if you want to use the Commercial Edition.
Type 'o' if you want to use the Open Source Edition.

当然选择o啦。继续提示:

This is the  Open Source Edition.

You are licensed to use this software under the terms of
the Lesser GNU General Public License (LGPL) versions 2.1.
You are also licensed to use this software under the terms of
the GNU General Public License (GPL) versions 3.

Type '3' to view the GNU General Public License version 3.
Type 'L' to view the Lesser GNU General Public License version 2.1.
Type 'yes' to accept this license offer.
Type 'no' to decline this license offer.

Do you accept the terms of either license?

输入yes,回车即可。接下来就会生成makefile文件,配置过程十来分钟左右。配置完毕后执行make。

接下来可以吃个饭或者睡一觉,编译时间大概3个小时左右,比较漫长,耐心等待吧。

经过漫长的等待之后,执行sudo make install来安装,会安装到/usr/local/Trolltech/Qt-4.8.4目录下。安装时间比较短,大概需要几分钟左右,至此,安装完成。

小测试一下,运行 /usr/local/Trolltech/Qt-4.8.4/bin/designer ,看见 qt 启动,如下图所示,就说明QT已经安装成功。

image

其他配置


qmake这个命令需要进行环境变量的配置才能找到的到,我看了下我的系统里已经包含了这个命令了,只是路径不一样。测试如下:

root@emouse:/# qmake -v
Qmake version: 1.07a (Qt 3.3.8b)
Qmake is free software from Trolltech ASA.
root@emouse:/# which qmake
/usr/bin/qmake

在看一下qmake的属性

image

从这个地方可以看出qmake这个命令别链接到了/etc/alternatives/qmake,还是不清楚是啥地方来的命令,继续看!找到/etc/alternatives/qmake,在看一下属性就清楚了,可以看到这个地方又链接回去了,那么如果还使用qmake命令的话实际使用的是qmake-qt3,这样就会出现错误。image也可以使用以下命令快速查看:

root@emouse:/# ls /usr/bin/qmake -ln
lrwxrwxrwx 1 0 0 23 12月 14 21:06 /usr/bin/qmake -> /etc/alternatives/qmake
root@emouse:/# ls /etc/alternatives/qmake -ln
lrwxrwxrwx 1 0 0 18 12月 14 21:06 /etc/alternatives/qmake -> /usr/bin/qmake-qt3

通过以上的分析可以知道,解决这个问题有两种方法,一个就是更改qmake的链接,使得qmake这个命令链接到安装目录下我们安装版本的qmake,还有一种方法就是改环境变量。

先说更改链接的方法,通过上面的介绍,这个其实操作就比较直接和简单了,命令和实验结果如下:

root@emouse:/# rm /etc/alternatives/qmake 
root@emouse:/# ln -s /usr/local/Trolltech/Qt-4.8.4/bin/qmake /etc/alternatives/qmake
root@emouse:/# qmake -v
QMake version 2.01a
Using Qt version 4.8.4 in /usr/local/Trolltech/Qt-4.8.4/lib

可以看到,qmake已经成功更改为4.8.4版本。

第二种办法就是更改环境变量,这个我没有尝试,有兴趣的自己验证。

vi /home/defonds/.bashrc 用来修改用户环境变量,在文件后面添加以下信息

export QTDIR=/usr/local/Trolltech/Qt-4.8.4 
export PATH=$QTDIR/bin:$PATH  
export MANPATH=$QTDIR/man:$MANPATH  
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

再修改所有用户环境变量vi /etc/profile 同样在文件后添加上面的环境变量信息。这种方法应该同样可行。

Qt-creator的安装与配置


根据上面提供的网址下载qt creator在linux下的安装文件qt-creator-linux-x86-opensource-2.6.1.bin,下面的安装就比较简单了,首先更改文件属性,使它可执行。

chmod u+x qt-creator-linux-x86-opensource-2.6.1.bin

然后运行sudo ./qt-creator-linux-x86-opensource-2.6.1.bin

接下来就是非常熟悉的安装界面了。

image

安装完成即可。接下来就可以使用这个IDE来进行开发了,这样的界面是不是在linux下很难得呢?

image

 

初步的安装就到这里,下次继续写关于嵌入式开发平台的构建。

posted @ 2013-01-28 16:24  emouse  阅读(147618)  评论(6编辑  收藏  举报