【问题标题】:How to use AppImageTool to create package to run on older Linux如何使用 AppImageTool 创建包以在旧版 Linux 上运行
【发布时间】:2020-10-28 00:31:50
【问题描述】:

我正在尝试使用 appimagetool(https://appimage.org/) 创建 OCR 程序 tesseract(https://github.com/tesseract-ocr) 的单二进制可执行文件。我在 Ubuntu 19.10 上构建了 tesseract,我希望可执行文件在 Ubuntu 14.01 上运行。

注意:我无法控制旧版本的 Ubuntu,我需要后期版本 tesseract 中的功能。我已经尝试过 tesseract 的现有 AppImage,但它以类似于下面详述的方式失败。

在本教程之后:https://appiomatic.com/blog/creating-appimage-binary-manually-for-linux-from-your-app/ 我创建了一个具有必要布局的tesseract.AppDir

tesseract.AppDir/AppRun
tesseract.AppDir/.DirIcon
tesseract.AppDir/tesseract.desktop
tesseract.AppDir/tesseract.png
tesseract.AppDir/usr
tesseract.AppDir/usr/bin
tesseract.AppDir/usr/bin/tesseract
tesseract.AppDir/usr/lib
tesseract.AppDir/usr/lib/libtesseract.so.5
tesseract.AppDir/usr/lib/libtesseract.so.5.0.0
...
tesseract.AppDir/usr/share
tesseract.AppDir/usr/share/tessdata
tesseract.AppDir/usr/share/tessdata/eng.traineddata
...
tesseract.AppDir/usr/share/tessdata/tessconfigs
...

并创建了 AppImage:

[Ubuntu 19.10]$ ~/Downloads/appimagetool-x86_64.AppImage tesseract.AppDir
appimagetool, continuous build (commit effcebc), build 2084 built on 2019-05-01 21:02:41 UTC
Using architecture x86_64
/home/kingsley/Software/Tesseract/tesseract/tesseract.AppDir should be packaged as Tesseract-OCR-x86_64.AppImage
Generating squashfs...
Parallel mksquashfs: Using 6 processors
Creating 4.0 filesystem on Tesseract-OCR-x86_64.AppImage, block size 131072.
[=======================================================================================================================|] 1921/1921 100%

Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments, compressed xattrs
    duplicates are removed
Filesystem size 73511.40 Kbytes (71.79 Mbytes)
    30.95% of uncompressed filesystem size (237490.75 Kbytes)
Inode table size 5971 bytes (5.83 Kbytes)
    57.29% of uncompressed inode table size (10423 bytes)
Directory table size 1019 bytes (1.00 Kbytes)
    56.90% of uncompressed directory table size (1791 bytes)
Number of duplicate files found 0
Number of inodes 92
Number of files 78
Number of fragments 5
Number of symbolic links  3
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 11
Number of ids (unique uids + gids) 1
Number of uids 1
    root (0)
Number of gids 1
    root (0)
Embedding ELF...
Marking the AppImage as executable...
Embedding MD5 digest
Success

但是把它复制到旧系统,它就无法运行,说它丢失了libpng16.so.16

[Ubuntu14]$ ./Tesseract-OCR-x86_64.AppImage 
tesseract: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory

进一步的研究让我相信我必须手动复制所有依赖项。

所以在tesseract 可执行文件上使用ldd

[Ubuntu 19.10]$ ldd LOCAL_INSTALL/bin/tesseract 
    linux-vdso.so.1 (0x00007fffd7937000)
    libtesseract.so.5 => not found
    liblept.so.5 => /usr/lib/x86_64-linux-gnu/liblept.so.5 (0x00007f44c03d3000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f44c03b0000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f44c01c2000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f44c01a8000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f44bffb7000)
    libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f44bff7d000)
    libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f44bfef8000)
    libgif.so.7 => /usr/lib/x86_64-linux-gnu/libgif.so.7 (0x00007f44bfeed000)
    libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f44bfe6c000)
    libwebp.so.6 => /usr/lib/x86_64-linux-gnu/libwebp.so.6 (0x00007f44bfc03000)
    libopenjp2.so.7 => /usr/lib/x86_64-linux-gnu/libopenjp2.so.7 (0x00007f44bfbad000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f44bfa5c000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f44bfa40000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f44c0706000)
    libzstd.so.1 => /usr/lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f44bf999000)
    liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f44bf972000)
    libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f44bf764000)

然后我将所有这些共享库复制到 tesseract.AppDir/usr/lib/ 并再次重建 AppImage。

在 Ubuntu 14 上测试仍然失败:

[Ubuntu14]$ ./Tesseract-OCR-x86_64.AppImage 
Segmentation fault (core dumped)
Segmentation fault (core dumped)
Segmentation fault (core dumped)
Segmentation fault (core dumped)

编辑:我重试制作 AppImage,一一添加中间 .so 文件。只有当我最终复制 libc.so.6 时,我才得到了 seg。过错。但是,如果我不考虑这个库,则可执行文件运行会失败:

tesseract: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.22' not found (required by /tmp/.mount_Tesser6wDkZB/lib/liblept.so.5)

看来liblept.so.5是问题所在。

现在我几乎没有想法了。

  1. 不是 AppImages 的用例吗?
  2. 有没有办法调试出了什么问题?
  3. 有没有自动查找依赖的工具?
  4. Ubuntu 14.01 是否只是太旧目标,我应该放弃并重新使用gocr

【问题讨论】:

    标签: linux tesseract appimage


    【解决方案1】:

    这不是 AppImages 的用例吗?

    这肯定是一个有效的用例。

    有没有办法调试出了什么问题?

    是的,您可以使用straceLD_DEBUG=libs 环境变量来查看正在加载的内容。有关调试 AppImages 的更多信息,请查看:

    有没有自动查找依赖的工具?

    是的,请查看https://github.com/AppImage/awesome-appimage#build-systems

    您应该使用哪一个取决于您的应用是否可以构建在最古老的稳定系统上。如果答案是肯定的,您可以使用linuxdeploy,否则您可以使用appmage-builder。我建议阅读this entry 以了解使用的工具。

    Ubuntu 14.01 是不是太老了,我应该放弃并重新使用 gocr。

    可以证明,您可以使用appimage-builder 在 ubuntu 20.04 中构建您的 AppImage。

    【讨论】:

    • 非常感谢您的宝贵时间。这个答案为我指明了自己解决问题的正确方向。
    【解决方案2】:

    如果有人在这里寻找如何真正解决这个问题,我就是这样解决的。

    通过逐个添加库,我能够确定问题的核心是liblept.so.5 是用 GLIBC 22.2 编译的,而 Ubuntu 14 目标没有这个。我发现这是唯一有这个问题的库。

    然而,仅仅包含libc.so.6 也会导致所有这些分段错误。我不知道这是为什么 - 并且仍然想知道为什么。所以我四处寻找替代方案。

    我尝试的一种方法是编译 tesseract 以与静态 liblept 链接,但这并没有立即奏效,而且我没有时间对其进行全面调查。也许这是一个好方法。最终我打算编译一个本地 leptonica 库,这样就有一个原生 Ubuntu 14 版本的 .so,而 App Image 会使用它。

    显然这不是最好的解决方案,因为它没有被合并到包中,但这足以让它为我工作。

    【讨论】:

    • 如果没有配套的 ld-linux,您将无法使用 libc.so.6 二进制文件,还有其他密切相关的库也必须捆绑在一起。可以在以下位置找到这些文件的关闭列表:github.com/AppImageCrafters/appimage-builder/blob/master/…
    • 如果你捆绑了 libc.so.6 但你仍然从系统中加载了一些库(这是一种完全有效的方法)你将不得不在运行时检测并选择一个嵌入之间的较新的 lib 版本和系统中的那个。这是一篇关于主题azubieta.net/appimage/appimagebuilder/ld_so/glibc/2020/03/09/…的帖子
    • 作为最后的评论,我们已经在 appimage-builder 上解决了此类问题,并且对用户完全透明。所以如果你想/需要嵌入 libc.so.6 那么你应该使用 appimage-builder 确保。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 2011-04-11
    • 2017-04-24
    相关资源
    最近更新 更多