ubuntu下安装qt5.9.1进行编译出现问题解决方法
当Ubuntu安装好qt5.9.1后先将示例进行编译发现报错
qt安装包地址:http://download.qt.io/archive/qt/,本人下载的安装包是qt-opensource-linux-x64-5.9.1.run
打开终端,输入命令:“sudo chmod -R 777 qtopensource-linux-x64-5.7.0.run”,赋予安装包权限;
点击运行后报错,发现原来是没有安装GCC G++的编译器
打开终端,键入命令“sudo apt-get install gcc g++”,安装 linux 下编程的编译器;
因为本人装的是ubuntu20.04所以需要换源
通过gedit命令进行编辑软件源
sudo gedit /etc/apt/sources.list
如果报错提示:
sudo: gedit: command not found
那么直接使用vim修改:
vim /etc/apt/sources.list
顺便提一下vim的使用:进入后按i进入编辑模式(即INSERT插入),编辑完后先按Esc退出编辑模式,然后输入:wq 退出即可
打开源文件后如下
推荐使用阿里云源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
下面为清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-proposed main restricted universe multiverse
修改完软件源后,更新软件列表和软件:
sudo apt update
sudo apt upgrade
换完源后打开终端,键入命令“sudo apt-get install gcc g++”,安装 linux 下编程的编译器;
如果出现安装需要依赖则是软件源出现了问题,则需要再重新更换软件源,建议安装其他的阿里云源。
再输入命令“sudo apt-get install libqt4-dev”,不然编译时会出现错误“cannot find -lgl”;
再输入命令“sudo apt-get install build-essential”,这是一个编译工具,它可以使得我们的程序知道头文件和库函数放在哪个位置;
点击工具在下拉框中点击选项键
如上图,点击构建和运行,再点击构建套件,选择自动检测
选择如下图所示
选择完成后点击应用即可,配置完成。
再次运行 例程,结果如下图所示
表示配置完成
以上为qt在ubuntu的安装过程