当前测试环境是 Ubuntu18.04 桌面版本

1、安装工具

  • sudo apt-get install git g++ libgl1-mesa-dev
  • 当然你的Ubuntu肯定安装了QT工具,通过QCreator等工具编译出应用程序

2、下载 linuxdeployqt 工具

  • linuxdeployqt 官网:https://github.com/probonopd/linuxdeployqt
  • 进入 linuxdeployqt 修改文件 vim tools/linuxdeployqt/main.cpp 注释掉下面代码
// openSUSE Leap 15.0 uses glibc 2.26 and is used on OBS
// Ubuntu Xenial (16.04) uses glibc 2.23
// Ubuntu Bionic (18.04) uses glibc 2.27
/*
if (strverscmp (glcv, "2.28") >= 0) {qInfo() << "ERROR: The host system is too new.";qInfo() << "Please run on a system with a glibc version no newer than what comes with the oldest";qInfo() << "currently still-supported mainstream distribution (Ubuntu Bionic), which is glibc 2.27.";qInfo() << "This is so that the resulting bundle will work on most still-supported Linux distributions.";qInfo() << "For more information, please see";qInfo() << "https://github.com/probonopd/linuxdeployqt/issues/340";return 1;
}
*/

3、Cmake编译

  • 修改完上面(也不一定要修改,主要是防止glibc版本不同问题),linuxdeployqt 根目录下执行cmake CMakeLists.txt 做出 Makefile文件
  • sudo apt-get install cmake
yexiang@ubuntu:<linuxdeployqt>$ cmake CMakeLists.txt
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Updating excludelist...
CMake Warning at tools/linuxdeployqt/CMakeLists.txt:23 (message):Updating excludelist failed, using outdated copy-- Configuring done
-- Generating done
-- Build files have been written to: /home/yexiang/workspace/qt_package_tools/git_linuxdeployqt/linuxdeployqt
  • 执行make编译
yexiang@ubuntu:<linuxdeployqt>$ make
[ 20%] Automatic MOC for target linuxdeployqt
[ 20%] Built target linuxdeployqt_autogen
Scanning dependencies of target linuxdeployqt
[ 40%] Building CXX object tools/linuxdeployqt/CMakeFiles/linuxdeployqt.dir/main.cpp.o
/home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/main.cpp: In function ‘int main(int, char**)’:
/home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/main.cpp:544:83: warning: ‘QSet<T> QList<T>::toSet() const [with T = QString]’ is deprecated: Use QSet<T>(list.begin(), list.end()) instead. [-Wdeprecated-declarations]deploymentInfo.deployedLibraries = deploymentInfo.deployedLibraries.toSet().toList();^
In file included from /home/yexiang/Qt5.14.2/5.14.2/gcc_64/include/QtCore/qobject.h:49:0,from /home/yexiang/Qt5.14.2/5.14.2/gcc_64/include/QtCore/qcoreapplication.h:46,from /home/yexiang/Qt5.14.2/5.14.2/gcc_64/include/QtCore/QCoreApplication:1,from /home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/main.cpp:28:
/home/yexiang/Qt5.14.2/5.14.2/gcc_64/include/QtCore/qlist.h:413:13: note: declared hereQSet<T> toSet() const;^~~~~
/home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/main.cpp:544:92: warning: ‘QList<T> QSet<T>::toList() const [with T = QString]’ is deprecated: Use values() instead. [-Wdeprecated-declarations]deploymentInfo.deployedLibraries = deploymentInfo.deployedLibraries.toSet().toList();^
In file included from /home/yexiang/Qt5.14.2/5.14.2/gcc_64/include/QtCore/qdebug.h:52:0,from /home/yexiang/Qt5.14.2/5.14.2/gcc_64/include/QtCore/QDebug:1,from /home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/shared.h:34,from /home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/main.cpp:31:
/home/yexiang/Qt5.14.2/5.14.2/gcc_64/include/QtCore/qset.h:251:14: note: declared hereQList<T> toList() const { return values(); }^~~~~~
[ 60%] Building CXX object tools/linuxdeployqt/CMakeFiles/linuxdeployqt.dir/shared.cpp.o
[ 80%] Building CXX object tools/linuxdeployqt/CMakeFiles/linuxdeployqt.dir/linuxdeployqt_autogen/mocs_compilation.cpp.o
[100%] Linking CXX executable linuxdeployqt
[100%] Built target linuxdeployqt
  • 编译出的 linuxdeployqt 执行文件在 tools/linuxdeployqt 目录下
yexiang@ubuntu:<linuxdeployqt>$ pwd
/home/yexiang/workspace/qt_package_tools/git_linuxdeployqt/linuxdeployqt/tools/linuxdeployqtyexiang@ubuntu:<linuxdeployqt>$ ls -al
total 524
drwxrwxr-x 4 yexiang yexiang   4096 Sep  7 23:13 .
drwxrwxr-x 3 yexiang yexiang   4096 Sep  7 23:10 ..
-rwxrwxr-x 1 yexiang yexiang 366616 Sep  7 23:13 linuxdeployqt
...
  • 可以把编译出来的 linuxdeployqt 放到 /usr/local/bin 目录下,这样任何目录下都可以执行这个命令
  • sudo cp linuxdeployqt /usr/local/bin

4、测试

yexiang@ubuntu:<linuxdeployqt>$ pwd
/home/yexiang/workspace/qt_package_tools/git_linuxdeployqt/linuxdeployqt/tools/linuxdeployqtyexiang@ubuntu:<linuxdeployqt>$ mkdir test
yexiang@ubuntu:<linuxdeployqt>$ cd test/# 我这边放入一个 qtcreator 编译出来的执行文件
yexiang@ubuntu:<test>$ ls
helloworld# linuxdeployqt 执行打包命令如下
yexiang@ubuntu:<test>$ ../linuxdeployqt helloworld -appimage
linuxdeployqt 7 (commit 570ca2d), build <local dev build> built on 2021-09-08 03:10:09 UTC
Not using FHS-like mode
app-binary: "/home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/test/helloworld"
appDirPath: "/home/yexiang/workspace/qt_package_tools/linuxdeployqt/tools/linuxdeployqt/test"
relativeBinPath: "helloworld"
Keeping existing AppRun
ERROR: Could not start patchelf.
ERROR: Make sure it is installed on your $PATH.
ERROR: Error reading rpath with patchelf "libQt5Widgets.so" : ""
ERROR: Error reading rpath with patchelf "libQt5Widgets.so" : ""
  • 这里发现错误,没有 patchelf

5、安装 patchelf

  • 简单方法:sudo apt-get install patchelf
  • 源代码编译方法:
  • 下载代码:git clone https://github.com/NixOS/patchelf.git
yexiang@ubuntu:<patchelf>$ ls -al
total 112
drwxrwxr-x 6 yexiang yexiang  4096 Sep  7 23:48 .
drwxrwxr-x 3 yexiang yexiang  4096 Sep  7 23:48 ..
-rwxrwxr-x 1 yexiang yexiang    68 Sep  7 23:48 bootstrap.sh
-rw-rw-r-- 1 yexiang yexiang   191 Sep  7 23:48 BUGS
-rw-rw-r-- 1 yexiang yexiang   992 Sep  7 23:48 configure.ac
-rw-rw-r-- 1 yexiang yexiang 35147 Sep  7 23:48 COPYING
-rw-rw-r-- 1 yexiang yexiang   115 Sep  7 23:48 default.nix
-rw-rw-r-- 1 yexiang yexiang   538 Sep  7 23:48 flake.lock
-rw-rw-r-- 1 yexiang yexiang  2639 Sep  7 23:48 flake.nix
drwxrwxr-x 8 yexiang yexiang  4096 Sep  7 23:48 .git
drwxrwxr-x 4 yexiang yexiang  4096 Sep  7 23:48 .github
-rw-rw-r-- 1 yexiang yexiang   410 Sep  7 23:48 .gitignore
-rw-rw-r-- 1 yexiang yexiang   133 Sep  7 23:48 Makefile.am
-rw-rw-r-- 1 yexiang yexiang  2917 Sep  7 23:48 patchelf.1
-rw-rw-r-- 1 yexiang yexiang   838 Sep  7 23:48 patchelf.spec.in
-rw-rw-r-- 1 yexiang yexiang  5502 Sep  7 23:48 README.md
drwxrwxr-x 2 yexiang yexiang  4096 Sep  7 23:48 src
drwxrwxr-x 5 yexiang yexiang  4096 Sep  7 23:48 tests
-rw-rw-r-- 1 yexiang yexiang     4 Sep  7 23:48 version
  • 编译过程:
yexiang@ubuntu:<patchelf>$ ./bootstrap.sh
./bootstrap.sh: 2: ./bootstrap.sh: autoreconf: not found# 缺少autoreconf,安装autoreconf
# 安装工具: sudo apt-get install autoconf# 安装后再次运行上面的代码 生成 configure 文件# ./configure 生成 makefile文件
yexiang@ubuntu:<patchelf>$./configure
# make 命令编译
yexiang@ubuntu:<patchelf>$make -j
# make check 可以检查编译过程是否ok
yexiang@ubuntu:<patchelf>$make check# 把编译出来的 patchelf文件安装到 /usr/local/bin 目录下
yexiang@ubuntu:<patchelf>$sudo make install# 查看patchelf
yexiang@ubuntu:<tools>$ which patchelf
/usr/local/bin/patchelf
  • 编译后的目录如下:
yexiang@ubuntu:<patchelf>$ ls -al
total 444
drwxrwxr-x 8 yexiang yexiang   4096 Sep  7 20:39 .
drwxrwxr-x 5 yexiang yexiang   4096 Sep  7 23:09 ..
-rw-rw-r-- 1 yexiang yexiang  42915 Sep  7 20:39 aclocal.m4
drwxr-xr-x 2 yexiang yexiang   4096 Sep  7 20:39 autom4te.cache
-rwxrwxr-x 1 yexiang yexiang     68 Sep  7 20:37 bootstrap.sh
-rw-rw-r-- 1 yexiang yexiang    191 Sep  7 20:37 BUGS
drwxr-xr-x 2 yexiang yexiang   4096 Sep  7 20:39 build-aux
-rw-rw-r-- 1 yexiang yexiang  13147 Sep  7 20:39 config.log
-rwxrwxr-x 1 yexiang yexiang  29797 Sep  7 20:39 config.status
-rwxrwxr-x 1 yexiang yexiang 161844 Sep  7 20:39 configure
-rw-rw-r-- 1 yexiang yexiang    992 Sep  7 20:37 configure.ac
-rw-rw-r-- 1 yexiang yexiang  35147 Sep  7 20:37 COPYING
-rw-rw-r-- 1 yexiang yexiang    115 Sep  7 20:37 default.nix
-rw-rw-r-- 1 yexiang yexiang    538 Sep  7 20:37 flake.lock
-rw-rw-r-- 1 yexiang yexiang   2639 Sep  7 20:37 flake.nix
drwxrwxr-x 8 yexiang yexiang   4096 Sep  7 20:37 .git
drwxrwxr-x 4 yexiang yexiang   4096 Sep  7 20:37 .github
-rw-rw-r-- 1 yexiang yexiang    410 Sep  7 20:37 .gitignore
-rw-rw-r-- 1 yexiang yexiang  28749 Sep  7 20:39 Makefile
-rw-rw-r-- 1 yexiang yexiang    133 Sep  7 20:37 Makefile.am
-rw-rw-r-- 1 yexiang yexiang  28185 Sep  7 20:39 Makefile.in
-rw-rw-r-- 1 yexiang yexiang   2917 Sep  7 20:37 patchelf.1
-rw-rw-r-- 1 yexiang yexiang    825 Sep  7 20:39 patchelf.spec
-rw-rw-r-- 1 yexiang yexiang    838 Sep  7 20:37 patchelf.spec.in
-rw-rw-r-- 1 yexiang yexiang   5502 Sep  7 20:37 README.md
drwxrwxr-x 3 yexiang yexiang   4096 Sep  7 20:40 src
drwxrwxr-x 7 yexiang yexiang  12288 Sep  7 20:40 tests
-rw-rw-r-- 1 yexiang yexiang      4 Sep  7 20:37 version
​

6、回到4步骤再次运行打包

yexiang@ubuntu:<test>$ ../linuxdeployqt helloworld -appimage
linuxdeployqt 7 (commit 570ca2d), build <local dev build> built on 2021-09-08 06:12:43 UTC
Not using FHS-like mode
app-binary: "/home/yexiang/workspace/qt_package_tools/git_linuxdeployqt/linuxdeployqt/tools/linuxdeployqt/test/helloworld"
appDirPath: "/home/yexiang/workspace/qt_package_tools/git_linuxdeployqt/linuxdeployqt/tools/linuxdeployqt/test"
relativeBinPath: "helloworld"
ERROR: Desktop file missing, creating a default one (you will probably want to edit it)
ERROR: Icon file missing, creating a default one (you will probably want to edit it)
WARNING: Plugin "/home/yexiang/Qt5.14.2/5.14.2/gcc_64/plugins/platformthemes/libqgtk2.so" not found, skipping
WARNING: Plugin "/home/yexiang/Qt5.14.2/5.14.2/gcc_64/plugins/styles/libqgtk2style.so" not found, skipping
sh: 1: appimagetool: not foundyexiang@ubuntu:<test>$ ls
AppRun  default.desktop  default.png  doc  helloworld  lib  plugins  qt.conf  translations

目前6步骤 test 目录 放到其他机器上可以运行,后面还有一点等下补充,如打包成 appimage格式和 run格式

Linux系统打包QT程序相关推荐

  1. Linux环境打包Qt程序并部署到Docker容器

    Linux环境打包Qt程序并部署到Docker容器 根据项目需要,将UKylin版本的qt应用程序打包并且部署到docker容器中 系统版本 UKylin版本:Ubuntu18.04 Docker镜像 ...

  2. Window系统打包QT程序

    1.为什么打包 有时候我们编译出来的QT程序要给别人用,那么别人的电脑上可能没有安装QT,QT版本不同,或者其他因素的影响导致运行不了我们的程序,那么就需要打包给别人,把程序运行时候需要的一些库等资源 ...

  3. Linux下打包qt程序,可以发布到一台纯净的linux发行版系统上

    1.把你要发布的程序单独放到一个文件夹下 2.在文件夹下创建一个sh脚本名为pack.sh 输入以下内容 #!/bin/sh exe="app" #你需要发布的程序名称 des=& ...

  4. linux下qt多个程序打包,解决Ubuntu下使用linuxdeployqt打包Qt程序问题

    写了点Qt界面程序,然而发现很难移植到其他没有安装Qt环境的电脑上运行.查资料了解到,在windows上有windowsdeployqt程序,linux上有linuxdeployqt可以帮助我们快速打 ...

  5. linux下将qt程序打包成appimage程序

    linux下将qt程序打包成appimage程序 一.环境准备 1.1下载linuxdeployqt的程序(打包qt程序的工具) https://github.com/probonopd/linuxd ...

  6. linux下使用AppImage打包qt程序

    linux下使用AppImage打包qt程序 下载工具 1.1 linuxdeployqt 下载地址:https://github.com/probonopd/linuxdeployqt/releas ...

  7. Mac下使用macdeployqt打包qt程序:

    概述 初次在Mac上使用qt的macdeployqt来打包生成的可执行程序,这里记录下.由于我的程序是调用之前生成的qt动态库,而动态库又依赖于第三方库,相对于没有库文件依赖的程序,这里有一些需要注意 ...

  8. Mac 系统发布QT程序时,sqllite无法找到数据库,路径设置问题。

    Mac 系统发布QT程序时,sqllite无法找到数据库的问题,路径设置问题. Mac写的qt程序,使用了sqllite数据库,Qt里面release运行时可以连接数据库,正常使用.但是当运行rele ...

  9. linux系统运行MapReduce程序报错:exitCode 127

    linux系统运行MapReduce程序报错:exitCode 127 hadoop mapreduce 出现 /bin/bash: /bin/java: No such file or direct ...

最新文章

  1. apache2配置和使用
  2. python官网支持货到付款吗_官网购买的iPhone12pro还没发货?试着用Python快速入手...
  3. 42 Ansible配置
  4. 通过命令删除在ambari界面上无法删除节点上服务
  5. kali linux获取root,kali linux 安装keybase 并使用root来运行keybase
  6. MATLAB中将pgm图片二值化
  7. fan4801开关电源原理图_开关电源原理图各元件功能详解
  8. HDU5985 Lucky Conins 概率题
  9. html5 video修改默认样式,HTML5中将video设置为背景的方法
  10. 怎么去掉拼写检查的红线_发动机温度过高,水箱“开锅”,我们到底该怎么办?...
  11. php里push的用法,php array_push函数怎么用?
  12. Spring Cloud 之 Feign 使用HTTP请求远程服务
  13. linux下隐藏root进程,宝塔面板隐藏彩蛋 – btkill.py:Linux异常进程专杀
  14. window 快捷键
  15. UEFI+GPT安装Win10和RHEL6.5双系统
  16. Git过程中遇到Enter passphrase for key '/c/Users/XXX/.ssh/id_rsa':
  17. r语言 svycoxph_R语言之生信⑦Cox比例风险模型(单因素)
  18. 计算机专硕怎么规划未来?
  19. 《数字信号处理教程》利用matlab实现常用序列
  20. java商品类_编写java的一个商品类,急用,求大神帮忙,非常感谢

热门文章

  1. PyG利用GCN实现Cora、Citeseer、Pubmed引用论文节点分类
  2. 使用Fireworks 8制作网页效果图2-生成网页
  3. phoenix删除数据_李孟_新浪博客
  4. xml建模包括以下_()是专业建模语言。A.XMLB.UMLC.VC++D.JAVA - 信管网
  5. 计算机B的IP地址是,IP地址202.117.17.255/22是什么地址?()。A.网络地址B.全局 - 信管网...
  6. HTML网页播放器带列表,带有播放列表的网页播放器
  7. Spring2.5 综合应用探索
  8. eclipse工具卡死现象处理, 适用于sts
  9. Java函数调用重试的正确姿势
  10. ChatGPT专业应用:日报速成器