当前位置:首页 » 《随便一记》 » 正文

Ubuntu20 源码编译安装 QT6.0 教程【有详细图文,亲测可行】

24 人参与  2024年02月24日 19:16  分类 : 《随便一记》  评论

点击全文阅读


一、安装 Ubuntu

Virtual Box 版本: 7.0.6 r155176 (Qt5.15.2)

Ubuntu 版本:20.04.6 (amd64, Desktop LiveDVD)

二、安装 QT

# 官方下载https://download.qt.io/# 国内镜像下载https://mirrors.cloud.tencent.com/qt/https://mirrors-i.tuna.tsinghua.edu.cn# 参考官方安装文档https://doc.qt.io/archives/qt-6.0/linux-requirements.html#platform-plugin-dependencieshttps://doc.qt.io/archives/qt-6.0/linux-building.html# 下载 qt6.0https://mirrors.cloud.tencent.com/qt/archive/qt/6.0/6.0.0/single/qt-everywhere-src-6.0.0.zip

下载后解压,看一下 README 文件指导安装,

需要安装环境依赖,

# Perl 5.8 or later => https://www.perl.org/get.html# Python 2.7 or later# C++ compiler supporting the C++11 standard./configure -prefix $PWD/qtbase -opensource -nomake tests# make -j 4makemake install 

1、安装 Perl 5.38.0

wget https://www.cpan.org/src/5.0/perl-5.38.0.tar.gztar -zxvf perl-5.38.0.tar.gzcd perl-5.38.0/./Configure -des -Dprefix=$HOME/localperlmake testmake install

2、安装 gcc

sudo apt install gcc-9 g++-9

或者直接安装 GNU 集合,

sudo apt install build-essential

3、安装 Openssl

# https://www.openssl.org/source/sudo apt install zlib1g-dev# https://www.openssl.org/source/openssl-3.0.10.tar.gzwget https://www.openssl.org/source/openssl-3.0.10.tar.gztar -zxvf openssl-3.0.10.tar.gzcd openssl-3.0.10./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlibmake -j 4make install

4、安装 python

# 安装依赖sudo apt install libffi-devsudo apt install libgdbm-devtar -zxvf Python-3.8.8.tgzcd Python-3.8.8/./configure --prefix=/usr/local/python3 --with-ssl make -j 4make install

5、安装 QT

报错,这是不同系统编码格式导致,

bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory

解决:重置文件编码,

sudo apt-get install vim
vim configure:set ff:set ff=unix

报错 cmake: not found ,需要安装 Cmake, 

# https://cmake.org/download/# 解压tar -zxvf cmake-3.27.0.tar.gz# 进入目录cd cmake-3.27.0# 安装./bootstrap && make -j4 && sudo make install

 报错 Could NOT find OpenSSL ,需要安装 OpenSSL 依赖库,

sudo apt-get install libssl-dev

Cmake 安装完毕,重新配置 QT ,报错 LLVM and Clang C++ libraries have not been found ,

# 解决 https://clang.llvm.org/get_started.html# 安装 gitsudo apt-get install git# 克隆源代码#git clone --depth=1 https://github.com/llvm/llvm-project.gitgit clone -b llvmorg-15.0.7 https://gitee.com/openeuler/llvm-project.git# 进入目录cd llvm-project# 新建 build 目录mkdir build # 进入 build 目录cd build# 配置cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm# 编译make# 安装sudo make install

安装 LLVM 完毕,重新配置 QT,遇到 OpenGL 报错,

RROR: The OpenGL functionality tests failed!  You might need to modify the include and library search paths by editing QMAKE_INCDIR_OPENGL[_ES2], QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your platform.

解决,安装依赖,

sudo apt install libgl1-mesa-dev sudo apt install libglu1-mesa-dev

安装依赖后,要先清除配置缓存后重新配置,配置成功,然后执行编译安装,

报错 undefined reference to `typeinfo for clang::ASTConsumer',原因是 LLVM/Clang is built with RTTI disabled by default,

解决:修改 LLVM 配置,重新编译安装 LLVM,

# 配置cmake -DLLVM_ENABLE_RTTI=On -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm# 开启 RTTI 编译make -j4 REQUIRES_RTTI=1

./configure -prefix $PWD/qtbase -opensource -nomake tests

# make -j4 可能会报错,编译时切换一下命令cmake --build . --parallel

sudo make install

三、安装 QT Creator 

# 下载wget https://mirrors-i.tuna.tsinghua.edu.cn/qt/official_releases/qtcreator/11.0/11.0.2/qt-creator-opensource-linux-x86_64-11.0.2.run# 添加执行权限chmod +x qt-creator-opensource-linux-x86_64-11.0.2.run# 安装依赖库sudo apt-get install --assume-yes xfce4 xorg-dev libopencc2 libopencc2-data unzip zipsudo apt install --reinstall libxcb-xinerama0

# 指定安装目录/home/sam/qtcreator-11.0.2

 

四、简单示例

运行,报错找不到插件 "xcb",

qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc.

开启 Debug 模式,在项目中添加环境变量,

# 配置项目变量QT_DEBUG_PLUGINS=1

可以看到,搜索的是 QT 编译源码的目录路径,但实际上,QT Creator 安装目录下是有这个插件库的,尝试配置为 QT Creator 目录下的插件路径,

# 配置项目变量QT_QPA_PLATFORM_PLUGIN_PATH=/home/sam/qtcreator-11.0.2/lib/Qt/plugins/platforms

然而,QT Creator 目录下的插件路径并不生效,

最后解决方案:安装 XCB 库,

sudo apt install xcb

或者源码编译安装,

# 参考官方文档 https://xcb.freedesktop.org/DevelopersGuide/# 先安装软件包sudo apt-get install gcc git make automake autoconf libtool pkg-config libpthread-stubs0-dev libxml2-dev# 安装依赖库sudo apt-get install libxcb-util-devsudo apt-get install libxau-devsudo apt-get install libx11-dev# 下载wget https://xorg.freedesktop.org/archive/individual/proto/xcb-proto-1.15.tar.gzwget https://xorg.freedesktop.org/archive/individual/lib/libxcb-1.15.tar.gz# 解压tar -zxvf xcb-proto-1.15.tar.gztar -zxvf libxcb-1.15.tar.gz# 安装cd xcb-proto-1.15/./configure && make && sudo make installcd libxcb-1.15/./configure && make && sudo make install

# 默认在系统路径下/usr/local/include/xcb/usr/local/lib

配置环境变量,

# 配置环境变量 LD_LIBRARY_PATHsudo vim /etc/profileexport LD_LIBRARY_PATH=/usr/local/lib# 使配置生效source /etc/profile# 或者注册库sudo vim /etc/ld.so.conf# 在底部添加/usr/local/lib# 重新加载sudo /sbin/ldconfig

重新配置编译 QT,加上参数 -xcb ,不同版本的配置通过 ./configure --help 来配置参数,

# 配置./configure -prefix $PWD/qtbase -opensource -xcb -nomake tests

注意,配置信息一定要有 XCB yes 的提示,如果安装了 X11 依赖还是没有 yes,则使用 ninja 编译,

# X11 依赖参考 https://doc.qt.io/archives/qt-6.0/linux-requirements.html#platform-plugin-dependencies# 使用 ninjasudo apt install ninja-build# 重新配置./configure -prefix $PWD/qtbase -opensource -nomake tests -xcb# 编译安装cmake --build . --parallel 4

最终编译安装之后的插件产物有  libqxcb.so !

重新编译运行项目,正常启动!

五、总结

1、安装 Perl 、Python 、C++ compiler、Openssl、Cmake、LLVM、OpenGL 软件包与依赖

2、安装官网文档安装 X11 依赖

3、安装 XCB、ninja 

4、配置 QT 要有 -xcb 参数

./configure -prefix $PWD/qtbase -opensource -nomake tests -xcb

5、检查配置文件的 QPA 的 XCB 模块是否开启

6、使用 Cmake 编译安装 QT

7、安装 QT Creator ,配置组件 QT 路径


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/69821.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • (番外)+(全书)陆依霜轩辕翊(繁花盛意难平全书+后续+结局)_陆依霜轩辕翊免费列表_笔趣阁(繁花盛意难平全书+后续+结局)
  • 陌上离人终不归精编之作列表_陌上离人终不归精编之作(谢延安柳夕雾)
  • 谢延安柳夕雾(陌上离人终不归+后续+结局)结局_(谢延安柳夕雾陌上离人终不归+后续+结局全书结局)结局列表_笔趣阁(谢延安柳夕雾)
  • 五一出游,老婆执意住废弃酒店寻刺激全书+番外(阮丽丽秦枫)全书阮丽丽秦枫结局_阮丽丽秦枫结局列表_笔趣阁(五一出游,老婆执意住废弃酒店寻刺激全书+番外)
  • [从此音尘各悄然]完结版免费在线阅读_[萧淮柳如儿弟弟]悬念章节免费释出
  • 相爱十年,婚礼当天我假死了小说精彩节选免费试读_靳夕陈让明白小说章节免费试读
  • 全网独家(贺怀瑾魏雪瑶+后续+结局)魏雪瑶贺怀瑾_贺怀瑾魏雪瑶+后续+结局列表_笔趣阁(魏雪瑶贺怀瑾)
  • 霍昭珩谢诗蕊(谢诗蕊霍昭珩+后续+结局)结局_(霍昭珩谢诗蕊谢诗蕊霍昭珩+后续+结局全书结局)结局列表_笔趣阁(霍昭珩谢诗蕊)
  • 人面桃花长相忆+后续+番外在线品鉴(闻砚辞阮雾梨)_人面桃花长相忆+后续+番外在线品鉴闻砚辞阮雾梨
  • 闻砚辞阮雾梨结局+番外+后续(阮雾梨闻砚辞)全书阮雾梨闻砚辞结局_阮雾梨闻砚辞+结局列表_笔趣阁(闻砚辞阮雾梨结局+番外+后续)
  • [清风寄余年]节选免费试读
  • 宋清妤的凛冬散尽,永夜长明实力派宋清妤宋娇娇萧知凛全书在线

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1