最近在学习树莓派的编程,需要把程序打包发布,在树莓派上可以使用linuxdeployqt打报发布程序,具体步骤如下:
(1)安装patchelf、cmake
sudo apt install patchelf
sudo apt install cmake
(2)这一步是在ubuntu上可用,树莓派没有试过
配置qt环境变量,将下面代码写入/etc/profile内,Qt的版本号需要根据自己的qt版本号进行修改,写完后输入“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)下载lunuxdeployqt源码
终端输入指令: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、上述执行完毕后再输入:
make
3、生成linuxdeployqt,具体生成路径在:
xxx/linuxdeployqt/tools/linuxdeployqt
4、将可执行文件linuxdeployqt拷贝到/usr/local/bin,方便使用
cp linuxdeployqt /usr/local/bin
(6)打包
打包Qt生成的release程序,名为myapplication:
执行命令
linuxdeployqt myapplication -appimage
执行命令后会提示ico和desktop没有,但不影响。可以看到已经打包ok了。