当前测试环境是 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 here
QSet<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 here
QList<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/linuxdeployqt
yexiang@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/linuxdeployqt
yexiang@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 found
yexiang@ubuntu:<test>$ ls
AppRun default.desktop default.png doc helloworld lib plugins qt.conf translations
目前6步骤 test 目录 放到其他机器上可以运行,后面还有一点等下补充,如打包成 appimage格式和 run格式