转自Linux 下编译、安装、配置 QThtml
注意:编译安装耗时费力,且很容易出错,要不断调整编译参数,不推荐使用,不然这将会是一个纠结痛苦的过程。linux
打算作嵌入式图像处理,计划方案嵌入式Linux+OpenCV+QT,昨天简单入门OpenCV今天看看QT,QT就先弄Linux下面的,回家以前争取把基本的摸通,而后能在板子上跑起来。windows
Linux:Ubuntu 12.04 X86bash
QT:4.8.4工具
QT的早期版本和如今版本有点变化,提供的文件也不尽相同,最新的版本为5.0,我这里用的是4.8.4,一个完整的QT应该包括QT库、IDE也就是QT creator,在Linux下的安装中,目前看到的主要有三种方法:post
一、.bin文件直接安装,文件名为qt-sdk-……,一个./bin直接包括了全部相关工具,安装起来最为简单方便,可是目前的4.8.4在几个网站上已经找不到总的sdk的bin文件了,老版本的仍是能够的。学习
二、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
三、这就是本文用的方法,就是下载源码包,本身编译安装,最为麻烦,可是原本就是学习的,何况如今只能下载到源码包,那就先学习这种方法把。网站
QT有好几个下载网站,这里汇总介绍,自从诺基亚公司放弃Meego、遣散Qt开发团队之后,Qt商业版本的网站移到了qt.digia.com,而开源版本则放到了qt-project.org :ui
一、首先是诺基亚的官方网站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)
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
二、QT-project网站下载 http://qt-project.org/downloads
这个网站就直接并且清晰多了,分类很清楚,以下图所示。
须要说明的是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文件,能够直接安装。
一、拷贝文件到本身想要的文件夹,解压:
tar zxvf qt-everywhere-opensource-src-4.8.4.tar.gz
二、进入解压后文件目录,执行配置
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已经安装成功。
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的属性
从这个地方能够看出qmake这个命令别连接到了/etc/alternatives/qmake,仍是不清楚是啥地方来的命令,继续看!找到/etc/alternatives/qmake,在看一下属性就清楚了,能够看到这个地方又连接回去了,那么若是还使用qmake命令的话实际使用的是qmake-qt3,这样就会出现错误。也可使用如下命令快速查看:
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在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
接下来就是很是熟悉的安装界面了。
安装完成便可。接下来就可使用这个IDE来进行开发了,这样的界面是否是在linux下很可贵呢?
初步的安装就到这里,下次继续写关于嵌入式开发平台的构建。