打包软件工程及依赖环境成一个可执行文件

1. 任务背景

任务如题目,打包自己的C++工程及相应的依赖环境成一个可执行文件,方便别人使用看效果。这里使用Appimage的打包工具,这个能够将整个工程生成为一个可执行文件,再对模型加密即可。

2. 需要下载安装appimagetool

首先下载AppImage, 下载地址:
https://github.com/AppImage/appimagetool/releases

在这里插入图片描述

这个下载下来就可以,很简单,不需要安装,是个可执行文件可以直接跑。

3. 需要下载安装linuxdeploy

下载地址:[https://github.com/linuxdeploy/linuxdeploy/releases]
在这里插入图片描述
1)将下载的两个AppImage赋予可执行权限
2)使用linuxdeploy-x86_64.AppImage生成特定形式的文件夹APPDIR

./linuxdeploy-x86_64.AppImage --appdir=APPDIR -e ./build/source/offline-demo  --create-desktop-file --icon-file=offline-demo.png

注意:
(1) 要提供一个图标的png文件。
(2)文件的分辨率大小是有要求的,图标尺寸只能是:8x8, 16x16, 20x20, 22x22, 24x24, 28x28, 32x32, 36x36, 42x42, 48x48, 64x64, 72x72, 96x96, 128x128, 160x160, 192x192, 256x256, 384x384, 480x480或512x512 。
(3)png名称要与可执行文件的名称一致,否则会报错找不到
在这里插入图片描述
3)使用./appimagetool-x86_64.AppImage对上一阶段生成的文件夹APPDIR进行操作,生成最终的可执行文件。

./appimagetool-x86_64.AppImage APPDIR/

可能遇到的报错:

fuse: failed to exec fusermount3: No such file or directory

Cannot mount AppImage, please check your FUSE setup.
You might still be able to extract the contents of this AppImage 
if you run it with the --appimage-extract option. 
See https://github.com/AppImage/AppImageKit/wiki/FUSE 
for more information
open dir error: No such file or directory

ubuntu18.04系统下要安装一个fuse3, 有一丢丢麻烦,需要手动下载工程,进行源码安装,详见教程:
https://www.jianshu.com/p/0858d99f7e41

注意:
(1)在官网https://github.com/libfuse/libfuse/releases/tag/fuse-3.13.0下载了fuse3.13版本,里面的meson_version版本要求: ‘>= 0.42’,默认18.04ubuntu安装的meson为0.45.1,更高的fuse版本要求meson0.50,0.51以上。
(2)可能遇见如下报错:

appimagetool, continuous build (git version bfe6e0c), build 92 built on 2023-07-16 13:25:42 UTC
WARNING: zsyncmake command is missing, please install it if you want to use binary delta updates
Using architecture x86_64
/home/jiaozhu/code/orbbec_avatar/APPDIR should be packaged as offline-demo-x86_64.AppImage
WARNING: AppStream upstream metadata is missing, please consider creating it
         in usr/share/metainfo/offline-demo.appdata.xml
         Please see https://www.freedesktop.org/software/appstream/docs/chap-Quickstart.html#sect-Quickstart-DesktopApps
         for more information or use the generator at http://output.jsbin.com/qoqukof.
Generating squashfs...
Downloading runtime file from https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-x86_64
Downloaded runtime binary of size -1
Failed to download runtime file, please download the runtime manually fromhttps://github.com/AppImage/type2-runtime/releases and pass it to appimagetool with--runtime-file

手动再给出的github地址上下载runtime-x86_64,在生成最终AppImage时,传进去这个路径:

./appimagetool-x86_64.AppImage APPDIR/ --runtime-file "/home/zzz/code/runtime-x86_64"

终于生成了最后的AppImage文件:
在这里插入图片描述
运行发现:
在这里插入图片描述
这。。继续解决问题,干他丫的,发现也有人遇见相同的问题,Appimage无法打开的bug
解决问题的方法比较折中,将自己生成的appimage文件进行提取,会在对应路径中生成一个名为squashfs-root的文件夹,运行里面的AppRun文件,即可运行自己打包好的程序。

./offline-demo-x86_64.AppImage --appimage-extract
cd squashfs-root/
./AppRun /home/zz/0808_fin /home/zz/0803.engine /home/zz/0803.trt 1000.0 //代码必须传进去的几个参数

4. 大概率会遇到的其他问题

最后一步,把这个文件夹squashfs-root拷到别的电脑上,原来这才是问题的开始(耐心填坑就好)。

1)运行AppRun发现报错如下:

error while loading shared libraries:libnvinfer.so.8:cannot open shared object file:no such file or directory

解决方案:

要设置一下整个环境的lib路径

export LD_LIBRARY_PATH=/path/squashfs-root/usr/lib:$LD_LIBRARY_PATH

2)QT报错找不到xcb的问题

This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, xcb, xcb.
Reinstalling the application may fix this problem.

报错信息比较简短,就是找不到QT相关的库,查阅资料发现这是个打包比较常见的问题,打包的软件放到其他机器就有这个问题,解决方法:
设置环境变量

export QT_DEBUG_PLUGINS=1

加了这个环境变量,再运行可执行程序,可以看到QT程序加载的过程,能够看到详细的报错信息:
我的报错信息让我仔细检查路径下的platforms文件夹,我其实路径下没有这个文件夹,去原环境下,把QT的这个文件夹拷过来,会发现还是找不到库,动态链接xcb,显示缺少的依赖库信息,手动全部拷过来:

ldd /home/zzz/squashfs-root/platforms/libqxcb.so | grep "not found"

在这里插入图片描述
3)要跑代码的机器要保证有英伟达的驱动程序,否则跑模型的时候会报cuda error,以及cuda, 没有cuda, 也会报找不到libcudnn_ops_infer.so.8这个库的问题。
最后一部分是这样的:

【弯路之不必看版本
(https://github.com/linuxdeploy/linuxdeploy/releases)
https://github.com/linuxdeploy/linuxdeploy
编译这个工程需要一些依赖库,
1)PATCHELF库:
sudo apt install patchelf
2) CImg:
地址:https://github.com/GreycLab/CImg
下载后运行下面命令即可

sudo cp -r ./CImg.h /usr/local/include

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一位不愿暴露自己的小可爱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值