ubuntu16.04安装QT、QT Creator

Linux主机环境:ubuntu 16.04   64位版本   gcc 5.4.0  

root@suse:/proc# cat /proc/version
Linux version 4.15.0-45-generic (buildd@lcy01-amd64-027)
(gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)) 
#48~16.04.1-Ubuntu SMP Tue Jan 29 18:03:48 UTC 2019

1.下载QT和QT Creator源码

推荐下载站点:清华大学开源镜像站

QT:qt-everywhere-opensource-src-4.7.0.tar

QT Creator:qt-creator-opensource-linux-x86_64-4.0.2.run

2.安装QT Creator

其实安装顺序无所谓,QT Creator安装快一点,就先安装它了。

 qt-creator-opensource-linux-x86_64-4.0.2.run 拷贝到ubuntu下

执行:

chmod +x qt-creator-opensource-linux-x86_64-4.0.2.run

./qt-creator-opensource-linux-x86_64-4.0.2.run

之后便会出现如下图形安装界面,点击下一步。

这里选择qt creator的安装目录,后面的步骤就不一一介绍了,一路next即可。

安装完成之后,我们去往这个目录执行:

cd /opt/qtcreator-4.0.2/bin

./qtcreator

接着,就会弹出qt creator的图形界面了。

qt creator就安装完成了。

3.安装QT

这部分需要编译QT源码,需要的时间比较长。

首先将qt-everywhere-opensource-src-4.7.0.tar拷贝到Linux下并解压,再进入源码主目录:

tar -xvf qt-everywhere-opensource-src-4.7.0.tar.gz 

cd /qt-everywhere-opensource-src-4.7.0

接着执行./configure -prefix /usr/local/Qt-4.7.2 进行配置,/usr/local/Qt-4.7.2是指定安装目录,可以自定义

然后会询问edition,填写 “o”,即开源版本;

接着询问是否同意协议,填写yes。

root@suse:/qt/qt-everywhere-opensource-src-4.7.0# ./configure -prefix /usr/local/Qt-4.7.2
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 Qt for Linux/X11 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

Creating qmake. Please wait...
make: Nothing to be done for 'first'.
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 in /qt/qt-everywhere-opensource-src-4.7.0/mkspecs/linux-g++-64.

这时出现了一个报错:

Basic XLib functionality test failed!

不要慌张,这是因为libx11库缺失导致的,我们安装缺少的库即可。

apt-get install libx11-dev
apt-get install libxext-dev libxtst-dev

安装完成后,再次执行./configure -prefix /usr/local/Qt-4.7.2 进行配置,应该没有什么问题了,接下来会自动生成MakeFile文件.

  1. 执行Make,耐心等待10分钟左右。
  2. 编译完成,执行make install 安装,这个步骤大概2分钟左右。
  3. 安装完成后,进入/usr/local/Qt-4.7.2/bin目录,执行./designer

若整个过程没有错误,就会看下如下界面: 

注意:若这个界面出现乱码或者中文不显示,执行同目录下的./qtconfig配置字体。

第二个选项卡,Family选择宋体,然后保存退出即可。

接下来还需要配置环境变量。

  • 编辑/etc/profile,在末尾添加如下内容
 export QTDIR=/usr/local/Qt-4.7.2 
 export PATH=$QTDIR/bin:$PATH  
 export MANPATH=$QTDIR/man:$MANPATH  
 export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

然后执行 qmake -v

root@suse:/usr/local/Qt-4.7.2# qmake -v
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory

报错:No such file or directory,原因是qmake的路径不对,系统默认的qmake是个链接文件,链接到一个名为qtchooser的文件。

 修改下配置文件,把里面的路径替换为刚刚安装的QT路径:

vim /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

删除文件中原有的配置,把我们刚刚安装的QT路径添加进去:

最后执行qmake -v 

至此,QT已经安装完成,最后,打开QT Creator写一个简单的程序测试下。

编译期间可能会遇到以下错误:

1.编译出现找不到 cdefs.h / c++config.h

如遇到缺少 sys/cdefs.h 的情况,输入以下命令安装标c库

sudo apt-get install  build-essential libc6-dev libc6-dev-i386

如遇到缺少 bits/c++config.h的情况,输入以下命令安装gcc编译相关库

sudo apt-get install gcc-4.7-multilib g++-4.7-multilib


2.fatal error: bits/c++config.h: No such file or directory

在QT creator 中,想编译32bit的程序,结果编译的时候,出现了题中的错误。

那是系统还没有安装多版本编译模式的缘故,安装如下插件即可。

sudo apt-get install gcc-multilib g++-multilib

如果上面的安装最新版失败了,也可以尝试下面的版本。

sudo apt-get install gcc-4.8-multilib g++-4.8-multilib

猜你喜欢

转载自blog.csdn.net/qq_24835087/article/details/104378917