linux-ubuntu下使用linuxdeployqt+appimagetool将qt程序打包成xxx.AppImage文件

下文中提及的inuxdeployqt   patchelf    appimagetool工具及示例下载地址:

链接: https://pan.baidu.com/s/1BGm_btMIe75uW9hOC09Xlg

提取码: 7ayh 

 

需要创建目录及文件

xxx.AppDir

xxx.AppDir/AppRun-----------------------------------xx.AppImage运行时执行的程序,AppRun可以是可执行程序,也可以是脚本文件。

xxx.AppDir/usr

xxx.AppDir/usr/bin/xx--------------------------------主程序

xxx.AppDir/usr/lib-----------------------------------库目录

xxx.AppDir/usr/share/applications/xx.desktop---------界面程序启动文件

xxx.AppDir/usr/share/icons/hicolor/xx.png------------界面程序图标

 

打包步骤

一、准备打包文件

将 linuxdeployqt   patchelf    appimagetool等文件 拷贝到系统目录下   /bin    并赋予可执行权限chmod a+x 

将终端切换到xxx.AppDir同级的目录下

qt程序的打包先执行以下命令,将依赖库自动收集到xx.AppDir/usr目录下

linuxdeployqt xx.AppDir/usr/share/applications/xx.desktop

              xx.desktop和xx.png文件会被拷贝到xx.AppDir目录下

非qt程序的打包需要先将

            xx.desktop和xx.png文件手动放到xx.AppDir目录下

linux-ubuntu下使用linuxdeployqt+appimagetool将qt程序打包成xxx.AppImage文件_第1张图片

linux-ubuntu下使用linuxdeployqt+appimagetool将qt程序打包成xxx.AppImage文件_第2张图片

linux-ubuntu下使用linuxdeployqt+appimagetool将qt程序打包成xxx.AppImage文件_第3张图片

linux-ubuntu下使用linuxdeployqt+appimagetool将qt程序打包成xxx.AppImage文件_第4张图片

二、将AppRun放到xx.AppDir目录下

三、执行打包 命令    appimagetool  xx.AppDir

linux-ubuntu下使用linuxdeployqt+appimagetool将qt程序打包成xxx.AppImage文件_第5张图片

 

AppRun示例如下:

#!/bin/sh

SELF=$(readlink -f "$0")

HERE=${SELF%/*}

export PATH="${HERE}/usr/bin/:${HERE}/usr/sbin/:${HERE}/usr/games/:${HERE}/bin/:${HERE}/sbin/${PATH:+:$PATH}"

export LD_LIBRARY_PATH="${HERE}/usr/lib/:${HERE}/usr/lib/i386-linux-gnu/:${HERE}/usr/lib/x86_64-linux-gnu/:${HERE}/usr/lib32/:${HERE}/usr/lib64/:${HERE}/lib/:${HERE}/lib/i386-linux-gnu/:${HERE}/lib/x86_64-linux-gnu/:${HERE}/lib32/:${HERE}/lib64/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

export PYTHONPATH="${HERE}/usr/share/pyshared/${PYTHONPATH:+:$PYTHONPATH}"

export XDG_DATA_DIRS="${HERE}/usr/share/${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"

export PERLLIB="${HERE}/usr/share/perl5/:${HERE}/usr/lib/perl5/${PERLLIB:+:$PERLLIB}"

export GSETTINGS_SCHEMA_DIR="${HERE}/usr/share/glib-2.0/schemas/${GSETTINGS_SCHEMA_DIR:+:$GSETTINGS_SCHEMA_DIR}"

export QT_PLUGIN_PATH="${HERE}/usr/lib/qt4/plugins/:${HERE}/usr/lib/i386-linux-gnu/qt4/plugins/:${HERE}/usr/lib/x86_64-linux-gnu/qt4/plugins/:${HERE}/usr/lib32/qt4/plugins/:${HERE}/usr/lib64/qt4/plugins/:${HERE}/usr/lib/qt5/plugins/:${HERE}/usr/lib/i386-linux-gnu/qt5/plugins/:${HERE}/usr/lib/x86_64-linux-gnu/qt5/plugins/:${HERE}/usr/lib32/qt5/plugins/:${HERE}/usr/lib64/qt5/plugins/:${HERE}/usr/plugins/${QT_PLUGIN_PATH:+:$QT_PLUGIN_PATH}"

EXEC=$(grep -e '^Exec=.*' "${HERE}"/*.desktop | head -n 1 | cut -d "=" -f 2 | cut -d " " -f 1)

exec "${EXEC}" "$@"

 

xx.desktop示例如下:

[Desktop Entry]

Type=Application

Name=xx

Exec=xx

Comment=Tool to generate AppImages from AppDirs

Icon=logo

Categories=Development;

Terminal=false

 

 

 

参考

1、打包步骤参考

https://github.com/probonopd/linuxdeployqt/blob/master/BUILDING.md

打包过程中需要的软件 linuxdeployqt   patchelf    appimagetool   AppRun

集成包linuxdeployqt-5-x86_64.AppImage-----集成了linuxdeployqt   patchelf    

集成包appimagetool-x86_64.AppImage----------集成了appimagetool   AppRun

将qt5.8 打包成  QtCreator-5.8.0-x86_64.AppImage https://bintray.com/probono/AppImages/QtCreator/5.8.0#files

 

 

https://github.com/probonopd/linuxdeployqt/wiki/Custom-wrapper-script-instead-of-AppRun#example-wrapper-in-bash

  1. Create the appdir/ directories (appdir/usr/bin, appdir/usr/share/applications, ...).
  2. Create the wrapper script or program.
  1. Copy the main executables, not the wrapper, into appdir/usr/bin/.
  1. Copy the .desktop files into appdir/usr/share/applications/. Note that the desktop files' Exec=should still point to your executables, not the AppRun.
  1. Copy the icon file into appdir/usr/share/icons/hicolor/.
  1. Copy any other resources you may wish (Qml, etc).
  2. Run linuxdeployqt appdir/usr/share/application/*.desktop with any options you may need.
  3. Remove appdir/AppRun which is created by linuxdeployqt.
  4. Copy your wrapper in appdir/AppRun (i.e. to the place of the AppRun that was there).
  5. Run appimagetool appdir to create your image. (Note: there is a bug that may require you run this step twice).

 

AppRun 脚本的示例

#!/bin/bash
HERE="$(dirname "$(readlink -f "${0}")")"
export LD_LIBRARY_PATH=${HERE}/usr/lib/foobar:$LD_LIBRARY_PATH
exec "${HERE}/usr/bin/foo" "$@"

 

2、打包软件下载

https://github.com/probonopd/linuxdeployqt

https://github.com/AppImage/AppImageKit

 

你可能感兴趣的:(qt)