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."
相关推荐
小小小米粒16 分钟前
NAT 模式, 仅主机模式 Host-Only ,桥接模式 Bridge
linux·服务器·网络
沙漏无语4 小时前
(二)TIDB搭建正式集群
linux·数据库·tidb
思麟呀4 小时前
计算机网络初步认识
linux·计算机网络
浩子智控4 小时前
zynq嵌入式开发(2)—基本开发测试实例
linux·嵌入式硬件·硬件架构
闻道且行之4 小时前
Nginx 安装、做成服务及 HTTPS 配置全流程
linux·运维·nginx·https
昵称只能一个月修改一次。。。4 小时前
Linux系统编程:网络编程
linux·服务器·网络
猫猫的小茶馆4 小时前
【Linux 驱动开发】Linux 内核启动过程详解
linux·c语言·arm开发·驱动开发·stm32·单片机·mcu
人工智能训练5 小时前
Qwen3.5 开源全解析:从 0.8B 到 397B,代际升级 + 全场景选型指南
linux·运维·服务器·人工智能·开源·ai编程
蜕变的小白5 小时前
Linux系统编程-->UDP编程:C/S模型实战详解
linux·运维·网络协议·udp
linuxxx1105 小时前
让openclaw使用系统命令:“rm“, “mkdir“, “touch“, “ls“, “cat“, “echo“
linux·服务器·windows