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."
相关推荐
赖small强25 分钟前
【蓝牙】BLE 数据收发实战指南(手机 App ↔ 嵌入式 Linux/BlueZ)
linux·蓝牙·bluez·bluetoothctl·dbus-monitor·central·peripheral
wit_yuan27 分钟前
linux udp广播数据包实际用例
linux·服务器·udp
大聪明-PLUS27 分钟前
io_uring:Linux 上的高性能异步 I/O
linux·嵌入式·arm·smarc
qq_4798754336 分钟前
Linux time function in C/C++【2】
linux·c语言·c++
小武~1 小时前
嵌入式网络编程深度优化 --网络协议栈配置实战指南
linux·网络·网络协议
二进制星轨1 小时前
在 Ubuntu 上快速配置 Node.js 环境(附问题说明)
linux·ubuntu·node.js
kblj55551 小时前
学习Linux——网络——网卡
linux·网络·学习
Physicist in Geophy.2 小时前
新版ubuntu中sac安装问题(缺少libncurses5)
linux·运维·ubuntu
菲兹园长2 小时前
微服务组件(E、L、N、O、G)
linux·服务器·gateway
xier_ran2 小时前
Python从入门到精通:(2)Python 核心进阶教程从数据结构到面向对象
linux·windows·python·microsoft