ubuntu下发布应用,ldd脚本代替linuxdeployqt

ubuntu下发布应用,ldd脚本代替linuxdeployqt

主机环境 ubuntu22.04

下载linuxdeployqt 发现运行不起来,glbc版本不匹配

bash 复制代码
$ linuxdeployqt -v

linuxdeployqt  (commit 8cb9438), build 67 built on 2024-07-09 18:22:04 UTC
ERROR: The host system is too new.
Please run on a system with a glibc version no newer than what comes with the oldest
currently supported mainstream distribution (Ubuntu Focal Fossa), which is glibc 2.31.
This is so that the resulting bundle will work on most still-supported Linux distributions.
For more information, please see
https://github.com/probonopd/linuxdeployqt/issues/340

$ ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.8) 2.35
Copyright (C) 2022 自由软件基金会。
这是自由软件;复制本软件需满足的条件请参见源代码。本软件不提供任何
品质保证;甚至不保证适销性或是适用于某种特定用途。
由 Roland McGrath 和 Ulrich Drepper 编写。

所以用ldd脚本代替:

deployapp.sh

bash 复制代码
#!/bin/bash

# 检查是否提供了可执行文件路径
if [ -z "$1" ]; then
    echo "Usage: $0 <path-to-executable>"
    exit 1
fi

EXECUTABLE=$1
DEST_DIR="deploy"
LIB_DIR="$DEST_DIR/libs"

# 创建目标目录
mkdir -p "$LIB_DIR"

# 使用 ldd 查找可执行文件的依赖库
ldd $EXECUTABLE | grep "=> /" | awk '{print $3}' | while read -r lib; do
    echo "Copying $lib to $LIB_DIR"
    cp "$lib" "$LIB_DIR"
done

# 拷贝可执行文件到目标目录
cp "$EXECUTABLE" "$DEST_DIR"

# 使用 patchelf 修补可执行文件和库的路径
echo "Patching executable and libraries..."
patchelf --set-rpath '$ORIGIN/libs' "$DEST_DIR/$(basename $EXECUTABLE)"

find "$LIB_DIR" -type f -name "*.so*" | while read -r lib; do
    patchelf --set-rpath '$ORIGIN' "$lib"
done

echo "Deployment completed. Check the $DEST_DIR directory."
相关推荐
_考不上研究生不改名5 分钟前
【完美解决】VSCode连接HPC节点,已配置密钥却还是提示需要输入密码
linux·服务器·vscode·远程连接·hpc·超算集群
_长银40 分钟前
Vim搜索和替换
linux·编辑器·vim
爱的叹息2 小时前
Spring Boot 自定义配置类(包含字符串、数字、布尔、小数、集合、映射、嵌套对象)实现步骤及示例
java·linux·spring boot
嵌入式-老费2 小时前
Linux上位机开发实践(一个硬件算法加速的示例)
linux·运维·服务器
前进的程序员3 小时前
Linux C 与 C 语言的区别及开发差异
linux·运维·c语言
CZIDC3 小时前
华为昇腾服务器上查看固件、驱动和CANN版本的常用方法
linux·运维·服务器
良许Linux4 小时前
C++在嵌入式中表现如何?
linux
林政硕(Cohen0415)4 小时前
Linux驱动开发进阶(七)- DRM驱动程序设计
linux·驱动开发·drm
良许Linux4 小时前
能详细地讲讲stm32该怎么学吗?
linux
闭关苦炼内功5 小时前
linux 使用 usermod 授权 普通用户 属组权限
linux·运维