当前位置: 首页 > 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.dtcms.com/a/278435.html

相关文章:

  • Kotlin委托
  • 【Python】基础语法
  • 亚马逊新规!7月13日起合规性文件须出自符合要求的实验室!
  • 【飞牛云fnOS】告别数据孤岛:飞牛云fnOS私人资料管家
  • 【Hadoop科普篇】大数据怎么处理?Hadoop是什么?跟HDFS, Spark, Flink, Hive, Hbase是什么关系?
  • 嵌入式硬件篇---晶体管的分类
  • 大数据系列之:通过trino查询hive表
  • [Nagios Core] struct监控对象 | 配置.cfg加载为内存模型
  • Kotlin集合接口
  • HTTP 四种常见方法
  • 基于Hadoop的竞赛网站日志数据分析与可视化(上)
  • 基于hadoop的竞赛网站日志数据分析与可视化(下)
  • 神经网络与深度学习Python入门
  • 构建高效事件驱动架构:AWS S3与SQS集成实践指南
  • 实战:如何创建 AWS RDS 数据库
  • 显示器核心三要素详解:刷新率、分辨率、色深
  • 【JAVA】监听windows中鼠标侧面键的按钮按下事件
  • Web 前端面试
  • redis实现红锁
  • (1-7-3)数据库的基本查询
  • 【React Native】Switch、Alert、Dimensions、StatusBar、Image组件
  • 打破数据孤岛!医疗数据如何实现“可用不可见”?
  • OpenVela之开发自测试框架cmocka
  • 深入解析ThreadLocal:线程隔离的奥秘与内存泄漏解决方案
  • HarmonyOS从入门到精通:动画设计与实现之九 - 实用动画案例详解(上)
  • Linux操作系统从入门到实战(八)详细讲解编译器gcc/g++编译步骤与动静态库链接
  • C语言:20250714笔记
  • 更改elementui 图标 css content
  • Docker搭建Redis分片集群
  • kotlin学习笔记