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."
相关推荐
都在酒里22 分钟前
Linux字符设备驱动开发(十):综合实例——I2C传感器 + LED智能控制与进阶指南
linux·运维·服务器·驱动开发·交互
2301_809051148 小时前
Linux 网络编程 学习笔记
linux·网络·学习
坤昱8 小时前
cfs调度类深入解刨——最新内核细节分析2
linux·服务器·cfs·cfs调度·eevdf调度·eevdf·kernel 7.1
艾莉丝努力练剑8 小时前
【Linux:文件】Ext系列文件系统进阶
linux·运维·服务器·c++·文件系统·文件io·ext
海市公约8 小时前
Linux核心基础命令与权限管理实战指南
linux·运维·服务器·vim·权限管理·系统监控·命令行
eggcode9 小时前
【Qt学习】Linux(ARM架构)在线安装Qt6.x
linux·qt·学习·arm
wkd_0079 小时前
Ubuntu 22.04 Samba 连接故障排查记:从“用户名或密码错误”到 NTLM 版本不兼容
linux·运维·ubuntu
mixboot10 小时前
Linux 进程工作目录查看利器:pwdx 命令详解
linux·运维·服务器
旺仔来了11 小时前
不联网的Linux下部署python环境
linux·开发语言·python
Irene199112 小时前
WSL 切换磁盘后验证完整性(MobaXterm、Powershell、WSL 的区别)
linux·wsl·mobaxterm