在windows上有windeployqt程序,linux上有linuxdeployqt可以帮助我们快速打包。
官方有放出编译好的包,但是由于其支持版本极少。在使用中会提示:系统版本过高。因此还是选择编译代码的方式。
1、安装patchelf、cmake
sudo apt install patchelf
sudo apt install cmake
2、配置Qt环境变量
将下面代码写入/etc/profile内。完毕后输入"source /etc/profile"进行生效。
export PATH=/home/jxd/Qt5.12.8/5.12.8/gcc_64/bin:$PATH
export LD_LIBRARY_PATH=/home/jxd/Qt5.12.8/5.12.8/gcc_64/lib:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=/home/jxd/Qt5.12.8/5.12.8/gcc_64/plugins:$QT_PLUGIN_PATH
export QML2_IMPORT_PATH=/home/jxd/Qt5.12.8/5.12.8/gcc_64/qml:$QML2_IMPORT_PATH
3、下载 linuxdeployqt源码
终端输入指令:git clone https://github.com/probonopd/linuxdeployqt.git
4、将tools/linuxdeployqt/main.cpp中的下述代码注释掉:
// openSUSE Leap 15.0 uses glibc 2.26 and is used on OBS
/*
if (strverscmp (glcv, "2.27") >= 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 (xenial), which is glibc 2.23.";
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;
}*/
5、编译
1、在主linuxdeployqt目录下输入:
cmake CMakeLists.txt
2、上述执行完毕后再输入:
cmake
3、生成linuxdeployqt,具体生成路径在:
xxx/linuxdeployqt/tools/linuxdeployqt
4、将linuxdeployqt拷贝到/usr/local/bin,方便使用
cp linuxdeployqt /usr/local/bin
打包Qt生成的release程序,名为xx:
执行命令
linuxdeployqt xxx -appimage
执行命令后会提示ico和desktop没有,但不影响。可以看到已经打包ok了。
笔者 - jxd
微信公众号搜索 “码农总动员” 或 微信扫描下方二维码,了解更多你不知道的XX,O(∩_∩)O