天天看点

for linux qt 编译器的配置_linux 下安装编译配置 QT

注:

1,自己 make qt-everywhere-opensource-src s时,在./configure前主动装好以下3个

sudo apt-get install libX11-dev libXext-dev libXtst-dev\

还须要 apt-get install libxrandr-dev ,否则会有以下的报错,designer 界面乱码:

libxrandr-dev

X Error: BadDrawable (invalid Pixmap or Window parameter) 9

Major opcode: 62 (X_CopyArea)

Resource id:  0x0

2, 在/etc/profile 中加入 环境变量

export QTDIR=/usr/local/Trolltech/Qt-4.8.6

export PATH=$QTDIR/bin:$PATH

export MANPATH=$QTDIR/man:$MANPATH

export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

打算做嵌入式图像处理。计划方案嵌入式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-getinstall 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/  这个是不太方便的,想高速下载的接着看后面的。

此站点须要填写username和邮箱地址,下载地址会发送到邮件里,我就把我收到的地址贴出来吧。以下是邮件中的地址汇总。

这里面的linux源代码是commercial版本号。

Qt 4.8.4 for embedded Linux

Installing Qt for embedded Linux

Qt Commercial Charts 1.1.0

Qt 5.0.0 Sources

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

Qt Visual Studio Addin 1.1.11 for Qt4 (Binary)

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

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

Qt Creator 2.6.1 for Windows (32bit Binary)

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

Qt Commercial Charts 1.1.0

Qt 5.0.0 Sources

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

Qt Visual Studio Addin 1.2.0 for Qt5 (Binary)

这个站点就直接并且清楚多了,分类非常清楚,例如以下图所看到的。

for linux qt 编译器的配置_linux 下安装编译配置 QT

须要说明的是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、进入解压后文件文件夹。运行配置

[email protected]:~/study# cd qt-everywhere-opensource-src-4.8.4/

roo[email protected]:~/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行。例如以下:

for linux qt 编译器的配置_linux 下安装编译配置 QT

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

#prefix

if [ -z "$QT_INSTALL_PREFIX"]; thenif [ "$CFG_DEV" = "yes"]; then

QT_INSTALL_PREFIX="$outpath" #In Development, we use sandboxed builds by default

elif [ "$PLATFORM_QWS" = "yes" -o "$PLATFORM_QPA" = "yes"]; thenif [ "$PLATFORM_QPA" = "yes"]; then

QT_INSTALL_PREFIX="/usr/local/Trolltech/QtLighthouse-${QT_VERSION}"

elseQT_INSTALL_PREFIX="/usr/local/Trolltech/QtEmbedded-${QT_VERSION}"fiif [ "$PLATFORM" != "$XPLATFORM"]; then

QT_INSTALL_PREFIX="${QT_INSTALL_PREFIX}-${CFG_ARCH}"fi

elif [-d "$EPOCROOT" ] && [ "$XPLATFORM_SYMBIAN" = "yes"]; thenif [ "$XPLATFORM_SYMBIAN" = "yes"]; then

QT_INSTALL_PREFIX="$EPOCROOT/epoc32/"QT_INSTALL_LIBS="$EPOCROOT/epoc32/release/armv5/lib/"fielseQT_INSTALL_PREFIX="/usr/local/Trolltech/Qt-${QT_VERSION}" #the default install prefix is /usr/local/Trolltech/Qt-$QT_VERSION

for linux qt 编译器的配置_linux 下安装编译配置 QT

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

Which edition of Qt do you want to use ?Type'c' ifyou want to use the Commercial Edition.

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

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

for linux qt 编译器的配置_linux 下安装编译配置 QT

This isthe Open Source Edition.

You are licensed to usethissoftware under the terms of

the Lesser GNU General Public License (LGPL) versions2.1.

You are also licensed to usethissoftware under the terms of

the GNU General Public License (GPL) versions3.

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

Type'no' to decline thislicense offer.

Do you accept the terms of either license?

for linux qt 编译器的配置_linux 下安装编译配置 QT

输入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已经成功安装。

for linux qt 编译器的配置_linux 下安装编译配置 QT

其它配置

qmake这个命令须要进行环境变量的配置才干找到的到,我看了下我的系统里已经包含了这个命令了,仅仅是路径不一样。

測试例如以下:

[email protected]:/# qmake -v

Qmake version:1.07a (Qt 3.3.8b)

Qmakeis free software fromTrolltech ASA.

[email protected]:/# which qmake/usr/bin/qmake

在看一下qmake的属性

for linux qt 编译器的配置_linux 下安装编译配置 QT

从这个地方能够看出qmake这个命令别链接到了/etc/alternatives/qmake,还是不清楚是啥地方来的命令,继续看!

找到/etc/alternatives/qmake,在看一下属性就清楚了。能够看到这个地方又链接回去了。那么假设还使用qmake命令的话实际使用的是qmake-qt3,这样就会出现错误。

for linux qt 编译器的配置_linux 下安装编译配置 QT

也能够使用以下命令高速查看:

[email protected]:/# ls /usr/bin/qmake -ln

lrwxrwxrwx1 0 0 23 12月 14 21:06 /usr/bin/qmake -> /etc/alternatives/qmake

[email protected]:/# ls /etc/alternatives/qmake -ln

lrwxrwxrwx1 0 0 18 12月 14 21:06 /etc/alternatives/qmake -> /usr/bin/qmake-qt3

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

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

[email protected]:/# rm /etc/alternatives/qmake

[email protected]:/# ln -s /usr/local/Trolltech/Qt-4.8.4/bin/qmake /etc/alternatives/qmake

[email protected]:/# qmake -v

QMake version2.01a

Using Qt version4.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.4export 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

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

for linux qt 编译器的配置_linux 下安装编译配置 QT

安装完毕就可以。

接下来就能够使用这个IDE来进行开发了。这种界面是不是在linux下非常难得呢?

for linux qt 编译器的配置_linux 下安装编译配置 QT

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