Linux 下编译、安装、配置 QT
2016-05-02 09:48
771 查看
Linux 下编译、安装、配置 QT
打算做嵌入式图像处理,计划方案嵌入式Linux+OpenCV+QT,昨天简单入门OpenCV今天看看QT,QT就先弄Linux下面的,回家之前争取把基本的摸通,然后能在板子上跑起来。软件环境
Linux:Ubuntu 12.04 X86QT: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
这个网站就直接而且清晰多了,分类很清楚,如下图所示。
需要说明的是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[code].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的安装与配置
根据上面提供的网址下载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下很难得呢?
初步的安装就到这里,下次继续写关于嵌入式开发平台的构建。
★emouse 思·睿博客文章★ 原创文章转载请注明:http://emouse.cnblogs.com
分类: OpenCV&QT
好文要顶 关注我 收藏该文
emouse
关注 - 0
粉丝 - 266
+加关注
4
« 上一篇:OpenCV的第一个小程序:读取图像并显示
» 下一篇:Tslib和Qt
4.8.4与在开发板上的移植
posted @ 2013-01-28 16:24 emouse 阅读(64694) 评论(3) 编辑 收藏
评论列表
#1楼 2014-04-15
11:19 小饼和包子
请教一下,在为QT-creater配置时,在配置qt版本时,目录/usr/local/Trolltech/下的QtEmbedded-4.8.4-arm文件夹是什么时候产生的,以及是怎样产生的,求指导,谢谢
支持(1)反对(0)
#2楼 2015-03-20
13:12 勤·学·思·悟
补充一下:
在编译QT-X11 过程中遇到的错误提示为:
Basic XLib functionality test failed!
You might need to modify the include and library search paths by editing QMAKE_INCDIR_X11 and QMAKE_LIBDIR_X11 ... ...
这是因为之前没有安装 libxtst-dev !
解决办法:
输入 sudo apt-get install libxtst-dev,然后继续哦~
支持(0)反对(0)
#3楼 2015-09-27
19:58 cumtchw
第一次安装的时候,./configure后面跟了路径,结果安装失败,然后删除之后,重新配置,编译,这一次./config后面没有跟路径,结果安装成功了,但是在启动./designer 的时候,提示少了动态链接库,百度后发现是因为库的路径不对,在/etc/ld.so.conf中添加了路径之后,designer就能够正常启动了,写在这里,供以后遇到相同问题的人参考,
相关文章推荐
- Kali linux搭建钓鱼wifi
- Centos 7中 vim 中文乱码
- linux文件合并,去重
- CentOS 7 gedit编辑器中文乱码解决方法
- Linux查看硬件所有信息
- 鸟哥的Linux私房菜-Read_02
- debian + xfce解决不能自动挂载U盘问题
- Linux内核转发技术
- centos7支持ntfs
- centos7安装apue.3e时出错处理
- 在Linux以及Mac OS X启用F#
- [linux]结束进程
- centos下DNS搭建
- centOS6.4部署svn
- centos7下安装mplayer及其解码器和皮肤
- Linux基本命令01
- CentOS7搭建JEE环境
- linux CentOS 安装 arm 模拟器 SkyEye
- Linux Centos 系统上安装BT客户端 Transmission
- Linux Centos 系统上安装BT客户端 Transmission