ubuntu安装qt

ubuntu18.04安装qt5.15.10

安装qt

参考:
https://www.tal.org/tutorials/building-qt-515-lts-raspberry-pi-raspberry-pi-os

  1. 下载 qt 源码包

    下载地址:https://download.qt.io/archive/qt/5.15/5.15.10/single/qt-everywhere-opensource-src-5.15.10.tar.xz

  2. 安装qt编译依赖库

    1
    
    sudo apt-get install -y build-essential libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libcups2-dev zlib1g-dev
    
  3. 解压源码包并进入目录

    1
    2
    
    tar -xf qt-everywhere-src-5.15.10.tar.xz 
    cd qt-everywhere-src-5.15.10/
    
  4. 配置编译选项

    1
    
    ./configure -opensource -confirm-license -nomake examples -nomake tests -prefix /opt/app/qt-5.15.10
    
    • -opensource: 表示使用开源许可证
    • -confirm-license: 表示自动确认许可证
    • -nomake examples -nomake tests: 表示不编译示例和测试程序
    • -prefix: 指定安装位置,默认安装到 /usr/local/Qt-5.15.10 下
  5. 编译源码

    因为源码编译耗时特别长,所以最好加上 -j 参数,并行编译,加快编译速度

    1
    
    make -j8
    
  6. 安装qt

    1
    
    sudo make install
    
  7. 配置环境变量

    需要将Qt添加到PATH中,以便在终端中使用Qt命令行工具。可以编辑.bashrc文件,在末尾添加以下内容:

    1
    2
    
    export QTDIR=/opt/app/qt-5.15.10
    export PATH=QTDIR/bin:PATH
    

    保存并退出文件后,执行以下命令使其生效:

    1
    
    source ~/.bashrc
    

    也可以添加全局环境变量配置,新增 /etc/profile.d/qt.sh,内容如下

    1
    2
    3
    4
    5
    6
    
    #!/bin/bash
    export QTDIR=/opt/app/qt-5.15.10
    case ":$PATH:" in
        *":$QTDIR/bin:"*) :;; # already there
        *) PATH="$QTDIR/bin:$PATH";; # or PATH="$PATH:$new_entry"
    esac
    

安装 qt-creator

下载最新版的 qt-creator

下载地址:https://download.qt.io/official_releases/qtcreator/11.0/11.0.2/

1
2
chmod +x qt-creator-opensource-linux-x86_64-11.0.2.run
./qt-creator-opensource-linux-x86_64-11.0.2.run

问题

  1. 配置编译选项时出错:ERROR: The OpenGL functionality tests failed!

    1
    
    ./configure -opensource -confirm-license -nomake examples -nomake tests
    

    错误如下:

    1
    2
    3
    
    ERROR: 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.
    

    添加 -no-opengl,可以正常通过配置

    1
    
    ./configure -opensource -confirm-license -nomake examples -nomake tests -no-opengl
    

    猜测:系统没有安装opengl

    安装 opengl

    参考:
    https://crainyday.gitee.io/Ubuntu_004.html
    https://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Linux

    问题:安装 libgl1-mesa-dev 失败,提示无法安装libx11-xcb-dev

    手动安装 libx11-xcb-dev

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    
    hekai@00bafcjc-dUrwEMo9N5:~/Downloads$ sudo apt install libx11-xcb-dev
    正在读取软件包列表... 完成
    正在分析软件包的依赖关系树
    正在读取状态信息... 完成
    有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是
    因为系统无法达到您要求的状态造成的。该版本中可能会有一些您需要的软件
    包尚未被创建或是它们已被从新到(Incoming)目录移出。
    下列信息可能会对解决问题有所帮助:
    下列软件包有未满足的依赖关系:
    libx11-xcb-dev : 依赖: libx11-xcb1 (= 2:1.6.4-3ubuntu0.4) 但是 2:1.6.4-3ubuntu0.5 正要被安装
    E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。
    hekai@00bafcjc-dUrwEMo9N5:~/Downloads$ sudo apt list --installed | grep libx11-xcb1
    WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
    libx11-xcb1/now 2:1.6.4-3ubuntu0.5 amd64 [已安装,本地]
    

    由上可知,本系统已经安装了 libx11-xcb1 2:1.6.4-3ubuntu0.5,但是从仓库中安装 libx11-xcb-dev 时,仓库中的 libx11-xcb-dev 依赖 libx11-xcb1 2:1.6.4-3ubuntu0.4

    查看仓库中 libx11-xcb-dev 的版本,可以看到仓库中的 libx11-xcb-dev 版本是 2:1.6.4-3ubuntu0.4 amd64

    1
    2
    3
    4
    5
    6
    
    hekai@00bafcjc-dUrwEMo9N5:~/Downloads$ sudo apt search libx11-xcb-dev
    正在排序... 完成
    全文搜索... 完成
    libx11-xcb-dev/bionic-updates,bionic-security 2:1.6.4-3ubuntu0.4 amd64
    Xlib/XCB interface library (development headers)
    hekai@00bafcjc-dUrwEMo9N5:~/Downloads$
    

    有两个方法

    1. 卸载本机中的 libx11-xcb1 2:1.6.4-3ubuntu0.5 ,安装低版本的 libx11-xcb1 2:1.6.4-3ubuntu0.4,然后继续安装仓库中的 libx11-xcb-dev
    2. 找找有没有 2:1.6.4-3ubuntu0.5 版本的 libx11-xcb-dev

    第一个方法风险有点大,因为看到很多软件都依赖了 libx11-xcb1

    幸好找到了 2:1.6.4-3ubuntu0.5 版本的 libx11-xcb-dev,所以使用第二个方法。

    libx11-xcb-dev 2:1.6.4-3ubuntu0.5 下载地址:
    https://launchpad.net/ubuntu/bionic/amd64/libx11-xcb-dev/2:1.6.4-3ubuntu0.5

    libx11-xcb-dev 2:1.6.4-3ubuntu0.5 本地下载

    安装 libx11-xcb-dev 2:1.6.4-3ubuntu0.5

    1
    2
    3
    4
    5
    6
    7
    8
    
    hekai@00bafcjc-dUrwEMo9N5:~/Downloads$ sudo dpkg -i libx11-xcb-dev_1.6.4-3ubuntu0.5_amd64.deb
    正在选中未选择的软件包 libx11-xcb-dev:amd64。
    (正在读取数据库 ... 系统当前共安装有 285619 个文件和目录。)
    正准备解包 libx11-xcb-dev_1.6.4-3ubuntu0.5_amd64.deb  ...
    正在解包 libx11-xcb-dev:amd64 (2:1.6.4-3ubuntu0.5) ...
    正在设置 libx11-xcb-dev:amd64 (2:1.6.4-3ubuntu0.5) ...
    正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 ...
    hekai@00bafcjc-dUrwEMo9N5:~/Downloads$
    

    然后可以安装 opengl 了

    1
    
    sudo apt-get install build-essential libgl1-mesa-dev
    
  2. configure配置时由于存在缓存导致失败

    缓存可能会导致执行 ./configure 时失败

    解决办法:删除 configure.cache ,然后再执行 ./configure

  3. 启动 qtcreator ,没有响应

    查看日志 journalctl -f

    1
    
    qtcreator: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found
    

    安装 glibc_2.28

    参考:
    http://www.xbhp.cn/news/54783.html

    查看当前系统支持的 glibc : strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_

    在 /etc/apt/source.list 文件新增源

    1
    
    deb http://security.debian.org/debian-security buster/updates main 
    

    刷新软件包的缓存

    1
    
    sudo apt update
    

    apt-get update之后若出现下面提示:

    1
    
    由于没有公钥,无法验证下列签名: NO_PUBKEY 112695A0E562B32A NO_PUBKEY 54404762BBB6E853
    

    执行如下命令

    1
    2
    3
    4
    5
    6
    7
    
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A 54404762BBB6E853
    ``
    其中后面的112695A0E562B32A 54404762BBB6E853就是上面提到的NO_PUBKEY 112695A0E562B32A NO_PUBKEY 54404762BBB6E853中的公钥,替换成对应的即可。然后重新apt-get update。
    
    查看软件包可更新列表
    ```bash
    sudo apt list --upgradable 
    

    安装libc6

    1
    
    sudo apt install libc6-dev  /sudo apt install libc6
    

    查看服务器当前glibc版本:

    1
    
    strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_
    
Licensed under CC BY-NC-SA 4.0
Built with Hugo
主题 StackJimmy 设计