当前位置: 首页 > news >正文

ubuntu22.04下配置qt5.15.17开发环境

自从qt5.15版本开始,不再提供免费的离线安装包,只能通过源码自行编译。刚好最近需要在ubuntu22.04下配置qt开发环境,于是写篇文章记录配置的过程。

其实一开始是想配置qt5.15.2的,但是在编译配置参数这一步骤中出现如下报错

embedsky@embedsky-virtual-machine:/opt/qt-everywhere-src-5.15.2$ make clean
make: *** No rule to make target 'clean'.  Stop.
embedsky@embedsky-virtual-machine:/opt/qt-everywhere-src-5.15.2$ ./configure -prefix /opt/qt5.15.2 -opensource -confirm-license -nomake tests -nomake examples -c++std c++14
+ cd qtbase
+ /opt/qt-everywhere-src-5.15.2/qtbase/configure -top-level -prefix /opt/qt5.15.2 -opensource -confirm-license -nomake tests -nomake examples -c++std c++14
Creating qmake...
.In file included from /opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/qfloat16.h:1,from /opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qendian.h:44,from /opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/qendian.h:1,from /opt/qt-everywhere-src-5.15.2/qtbase/src/corelib/codecs/qutfcodec.cpp:43:
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:300:7: error: ‘numeric_limits’ is not a class template300 | class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float>|       ^~~~~~~~~~~~~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:300:77: error: expected template-name before ‘<’ token300 | class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float>|                                                                             ^
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:300:77: error: expected ‘{’ before ‘<’ token
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:344:18: error: ‘numeric_limits’ is not a class template344 | template<> class numeric_limits<const QT_PREPEND_NAMESPACE(qfloat16)>|                  ^~~~~~~~~~~~~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:344:69: error: ‘std::numeric_limits’ is not a template344 | template<> class numeric_limits<const QT_PREPEND_NAMESPACE(qfloat16)>|                                                                     ^
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:300:7: note: previous declaration here300 | class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float>|       ^~~~~~~~~~~~~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:345:28: error: expected template-name before ‘<’ token345 |     : public numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> {};|                            ^
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:346:18: error: ‘numeric_limits’ is not a class template346 | template<> class numeric_limits<volatile QT_PREPEND_NAMESPACE(qfloat16)>|                  ^~~~~~~~~~~~~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:346:72: error: ‘std::numeric_limits’ is not a template346 | template<> class numeric_limits<volatile QT_PREPEND_NAMESPACE(qfloat16)>|                                                                        ^
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:300:7: note: previous declaration here300 | class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float>|       ^~~~~~~~~~~~~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:347:28: error: expected template-name before ‘<’ token347 |     : public numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> {};|                            ^
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:348:18: error: ‘numeric_limits’ is not a class template348 | template<> class numeric_limits<const volatile QT_PREPEND_NAMESPACE(qfloat16)>|                  ^~~~~~~~~~~~~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:348:78: error: ‘std::numeric_limits’ is not a template348 | template<> class numeric_limits<const volatile QT_PREPEND_NAMESPACE(qfloat16)>|                                                                              ^
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:300:7: note: previous declaration here300 | class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float>|       ^~~~~~~~~~~~~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:349:28: error: expected template-name before ‘<’ token349 |     : public numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> {};|                            ^
In file included from /opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/qendian.h:1,from /opt/qt-everywhere-src-5.15.2/qtbase/src/corelib/codecs/qutfcodec.cpp:43:
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qendian.h: In static member function ‘static constexpr QSpecialInteger<S> QSpecialInteger<S>::max()’:
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qendian.h:331:30: error: ‘std::numeric_limits’ is not a template331 |     { return QSpecialInteger(std::numeric_limits<T>::max()); }|                              ^~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qendian.h:331:54: error: incomplete type ‘std::numeric_limits’ used in nested name specifier331 |     { return QSpecialInteger(std::numeric_limits<T>::max()); }|                                                      ^~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qendian.h: In static member function ‘static constexpr QSpecialInteger<S> QSpecialInteger<S>::min()’:
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qendian.h:333:30: error: ‘std::numeric_limits’ is not a template333 |     { return QSpecialInteger(std::numeric_limits<T>::min()); }|                              ^~~
/opt/qt-everywhere-src-5.15.2/qtbase/include/QtCore/../../src/corelib/global/qendian.h:333:54: error: incomplete type ‘std::numeric_limits’ used in nested name specifier333 |     { return QSpecialInteger(std::numeric_limits<T>::min()); }|                                                      ^~~
gmake: *** [Makefile:383: qutfcodec.o] Error 1 

从错误日志来看,核心问题是:
error: ‘numeric_limits’ is not a class template

一通操作还是没能解决,于是打算编译其他版本的qt试试,于是便选择了qt5.15.17

补充:后面根据这篇文章:Loading...https://bugreports.qt.io/browse/QTBUG-90395貌似这是编译qt5.15.2时都会出现的一个bug,这个bug已经在后面的补丁版本中修复。如果非要编译qt5.15.2,具体解决可以参考这篇博客:qt5.15.2源码编译出错处理_qt #include <limits>-CSDN博客


1.执行../qt-everywhere-src-5.15.2/configure -make libs -xplatform aarch64-buildroot-linux-gnu -no-opengl

报错如下: 5.15.2/qtbase/include/QtCore/../../src/corelib/global/qfloat16.h:300:7: error: ‘numeric_limits’ is not a class template   300 | class numeric_limits<QT_PREPEND_NAMESPACE(qfloat16)> : public numeric_limits<float>

解决:修改.qt-everywhere-src-5.15.2/qtbase/src/corelib/global/qglobal.h

增加#include <limits>

以下是编译qt5.15.17的过程

一、下载源码

清华源中下载源码Index of /qt/archive/qt/5.15/5.15.17/single/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

下载完后:cd qt-everywhere-src-5.15.17

源码目录如下

二、安装相关依赖包

sudo apt update
sudo apt install build-essential perl python3 git
sudo apt install '^libxcb.*' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxext-dev libxrandr-dev libxcursor-dev libfontconfig1-dev libdbus-1-dev libglib2.0-dev libssl-dev libpng-dev libjpeg-dev libglib2.0-dev
sudo apt install libglib2.0-bin
sudo apt install libxcb-xinerama0-dev libxkbcommon-x11-dev

三、编译配置选项

Qt5采用./configure脚本配置编译选项,我使用的命令如下:

./configure -prefix /opt/qt5.15.17 \
-opensource -confirm-license \
-nomake tests -nomake examples \
-c++std c++14 \
-opengl desktop \-no-use-gold-linker

参数解释:

-prefix:安装路径,建议使用自定义目录如/opt/qt5.15.17
-opensource:使用开源许可证
-confirm-license:自动确认许可协议
-nomake tests -nomake examples:不编译测试和示例,加快速度
-c++std c++14:Qt 5.15默认支持c++14,明确指定
-opengl desktop:使用系统OpenGL(如果需要软件渲染可以用-opengl software)
-no-use-gold-linker:避免使用gold链接器(有时防止编译问题)

如果还有其他编译需求,可以加更多参数

四、编译

执行

make -j4

编译过程可能耗时10~30分钟,具体取决于机器性能。

如果编译遇到make: *** No rule to make target 'clean'等错误,可以用make distclean或者直接删除源码目录重新解压。

五、安装

编译完成后执行:

sudo make install

会将Qt安装到-prefix指定的目录(/opt/qt5.15.17/)。

生成文件目录如下

六、配置qt环境变量

echo 'export PATH=/opt/qt5.15.17/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/qt5.15.17/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

七、验证

输入

qmake -v

输出类似以下即可

QMake version 3.1
Using Qt version 5.15.17 in /opt/qt5.15.17/lib

八、安装Qt Creator

在安装完后,发现没有像之前离线版本的方式打开Qt Creator。这是因为Qt Creator 是一个独立的 IDE,并不包含在 Qt 源码里,所以你自己编译 Qt 时并不会得到 Qt Creator。

所以需要另外下载Qt Creator

sudo apt update
sudo apt install qtcreator

下载完后可以看到

此时已经有完整的ide进行开发了

九、配置kit

编译源码的方式不会自动帮我们配置kit,需要自己手动配置

1、配置g++、gcc

2、配置qmake

3、配置kit

http://www.lryc.cn/news/587839.html

相关文章:

  • 2.查询操作-demo
  • 解决Chrome此扩展程序不再受支持,因此已停用
  • 代数基本定理
  • 史上最清楚!读者,写者问题(操作系统os)
  • 美联储降息趋缓叠加能源需求下调,泰国证券交易所新一代交易系统架构方案——高合规、强韧性、本地化的跨境金融基础设施解决方案
  • 软考 系统架构设计师系列知识点之杂项集萃(110)
  • 在Adobe Substance 3D Painter中,已经有基础图层,如何新建一个图层A,clone基础图层的纹理和内容到A图层
  • K8S的Helm包管理器
  • WebView 性能调试全流程:卡顿问题实战还原与优化路径解析
  • 基于 Gitlab、Jenkins与Jenkins分布式、SonarQube 、Nexus 的 CiCd 全流程打造
  • 考完数通,能转云计算/安全方向吗?转型路径与拓展路线分析
  • 计算机毕业设计Java医学生在线学习平台系统 基于 Java 的医学生在线学习平台设计与开发 Java 医学在线教育学习系统的设计与实现
  • 【云服务器安全相关】如何使用 `ping` 命令排查云服务器网络连接问题
  • Java实现文件自动下载,XXL-Job定时任务中的HTTP文件下载最佳实践
  • JAVA 设计模式 适配器
  • 设计模式之适配器模式:让不兼容的接口协同工作的艺术
  • 闲庭信步使用图像验证平台加速FPGA的开发:第十四课——图像二值化的FPGA实现
  • 使用aiohttp实现高并发爬虫
  • 未来手机会自动充电吗
  • vscode 源码编译
  • TCP半关闭
  • 使用layui的前端框架过程中,无法加载css和js怎么办?
  • 如何通过添加企业logo视频水印来对教育视频进行加密?
  • 8:从USB摄像头把声音拿出来--ALSA大佬登场!
  • GNhao,长期使用跨境手机SIM卡成为新趋势!
  • 控制台打开mysql服务报错解决办法
  • 我的Qt八股文面试笔记1:信号与槽文件流操作
  • Sharding-Sphere学习专题(四)广播表和绑定表、分片审计
  • 胡志明证券交易所新一代交易系统解决方案——基于美联储利率决议背景下的越南跨境金融基础设施升
  • 学习C++、QT---25(QT中实现QCombobox库的介绍和用QCombobox设置编码和使用编码的讲解)