ubuntu批量依赖库拷贝(ldd)

news/2024/12/22 16:31:51/

背景

如何将程序依赖的动态库拷贝到指定的目录?

例子

  1. 通过LDD查看依赖的动态库。
$ ldd extract_gpulinux-vdso.so.1 (0x00007ffd931e4000)libopencv_cudacodec.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_cudacodec.so.4.1 (0x00007f064e89f000)libopencv_cudaoptflow.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_cudaoptflow.so.4.1 (0x00007f064c710000)libopencv_videoio.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_videoio.so.4.1 (0x00007f064c4b8000)libopencv_imgcodecs.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_imgcodecs.so.4.1 (0x00007f064baf5000)libopencv_imgproc.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_imgproc.so.4.1 (0x00007f0649205000)libopencv_cudaarithm.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_cudaarithm.so.4.1 (0x00007f063d75c000)libopencv_core.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_core.so.4.1 (0x00007f063bac0000)libzip.so.4 => /usr/lib/x86_64-linux-gnu/libzip.so.4 (0x00007f063b8ac000)libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f063b523000)libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f063b30b000)libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f063af1a000)libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f063acfb000)libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f063aaf7000)librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f063a8ef000)/lib64/ld-linux-x86-64.so.2 (0x00007f064eded000)libopencv_cudawarping.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_cudawarping.so.4.1 (0x00007f0636519000)libopencv_cudalegacy.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_cudalegacy.so.4.1 (0x00007f063550e000)libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0635170000)libdc1394.so.22 => /usr/lib/x86_64-linux-gnu/libdc1394.so.22 (0x00007f0634efa000)libgstreamer-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0 (0x00007f0634bbf000)libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f063496b000)libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f0634654000)libgstapp-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgstapp-1.0.so.0 (0x00007f0634445000)libgstriff-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgstriff-1.0.so.0 (0x00007f0634237000)libgstpbutils-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgstpbutils-1.0.so.0 (0x00007f0633fff000)libavcodec.so.58 => /usr/local/lib/libavcodec.so.58 (0x00007f063295a000)libavformat.so.58 => /usr/local/lib/libavformat.so.58 (0x00007f063250a000)libavutil.so.56 => /usr/local/lib/libavutil.so.56 (0x00007f0632294000)libswscale.so.5 => /usr/local/lib/libswscale.so.5 (0x00007f0632009000)libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f0631da1000)libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f0631b6f000)libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f06318f8000)libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007f06316a3000)libz.so.1 => /usr/local/lib/libz.so.1 (0x00007f0631487000)libnppc.so.10 => /usr/local/cuda/lib64/libnppc.so.10 (0x00007f063120c000)libnppial.so.10 => /usr/local/cuda/lib64/libnppial.so.10 (0x00007f06304bd000)libnppidei.so.10 => /usr/local/cuda/lib64/libnppidei.so.10 (0x00007f062fad0000)libnppig.so.10 => /usr/local/cuda/lib64/libnppig.so.10 (0x00007f062e00a000)libnppist.so.10 => /usr/local/cuda/lib64/libnppist.so.10 (0x00007f062cc5e000)libnppitc.so.10 => /usr/local/cuda/lib64/libnppitc.so.10 (0x00007f062c775000)libcublas.so.10 => /usr/lib/x86_64-linux-gnu/libcublas.so.10 (0x00007f06284bf000)libcufft.so.10 => /usr/local/cuda/lib64/libcufft.so.10 (0x00007f062130a000)libtbb.so.2 => /usr/lib/x86_64-linux-gnu/libtbb.so.2 (0x00007f06210ce000)libopencv_cudaimgproc.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_cudaimgproc.so.4.1 (0x00007f061e7ac000)libopencv_objdetect.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_objdetect.so.4.1 (0x00007f061e546000)libopencv_cudafilters.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_cudafilters.so.4.1 (0x00007f0601d18000)libopencv_calib3d.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_calib3d.so.4.1 (0x00007f060197b000)libraw1394.so.11 => /usr/lib/x86_64-linux-gnu/libraw1394.so.11 (0x00007f060176c000)libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007f0601554000)libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f0601350000)libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f0601148000)libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f0600ed6000)libgstbase-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgstbase-1.0.so.0 (0x00007f0600c61000)libgstaudio-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgstaudio-1.0.so.0 (0x00007f06009ec000)libgsttag-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgsttag-1.0.so.0 (0x00007f06007b1000)libgstvideo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libgstvideo-1.0.so.0 (0x00007f0600518000)libswresample.so.3 => /usr/local/lib/libswresample.so.3 (0x00007f06002fb000)liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f06000d5000)libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f05ffec7000)libcublasLt.so.10 => /usr/lib/x86_64-linux-gnu/libcublasLt.so.10 (0x00007f05fe034000)libnppicc.so.10 => /usr/local/cuda/lib64/libnppicc.so.10 (0x00007f05fda56000)libnpps.so.10 => /usr/local/cuda/lib64/libnpps.so.10 (0x00007f05fcfd3000)libnppif.so.10 => /usr/local/cuda/lib64/libnppif.so.10 (0x00007f05fa099000)libnppim.so.10 => /usr/local/cuda/lib64/libnppim.so.10 (0x00007f05f989a000)libopencv_features2d.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_features2d.so.4.1 (0x00007f05f95c7000)libopencv_flann.so.4.1 => /home/joyner/disk1/mmaction/third_party/opencv-4.1.0/build/lib/libopencv_flann.so.4.1 (0x00007f05f936e000)libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007f05f9150000)liborc-0.4.so.0 => /usr/lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007f05f8ed4000)
  1. 写一个SHELL脚本,自动拷贝依赖的动态库。

vi release.sh

#!/bin/bash
deplist=$( ldd $1 | awk '{if (match($3,"/")){ print $3}}' )  
cp -L -n $deplist $2 
-L 表示拷贝文件(如果是软链,会拷贝到最终的文件)。 
-n 表示不覆盖已有文件。 
  1. 创建目标目录
mkdir release
  1. 将postgres依赖的动态库拷贝到目标目录
bash release.sh extract_gpu ./release/  
ll ./releasetotal 1.3G
drwxrwxr-x 2 joyner joyner 4.0K 6月   8 15:33 .
drwxrwxr-x 4 joyner joyner 4.0K 6月   8 15:33 ..
-rwxr-xr-x 1 joyner joyner  13M 6月   8 15:33 libavcodec.so.58
-rwxr-xr-x 1 joyner joyner 2.4M 6月   8 15:33 libavformat.so.58
-rwxr-xr-x 1 joyner joyner 411K 6月   8 15:33 libavutil.so.56
-rwxr-xr-x 1 joyner joyner 2.0M 6月   8 15:33 libc.so.6
-rwxr-xr-x 1 joyner joyner  29M 6月   8 15:33 libcublasLt.so.10
-rwxr-xr-x 1 joyner joyner  65M 6月   8 15:33 libcublas.so.10
-rwxr-xr-x 1 joyner joyner 112M 6月   8 15:33 libcufft.so.10
-rw-r--r-- 1 joyner joyner 216K 6月   8 15:33 libdc1394.so.22
-rw-r--r-- 1 joyner joyner  15K 6月   8 15:33 libdl.so.2
-rw-r--r-- 1 joyner joyner  31K 6月   8 15:33 libffi.so.6
-rw-r--r-- 1 joyner joyner  95K 6月   8 15:33 libgcc_s.so.1
-rw-r--r-- 1 joyner joyner 1.1M 6月   8 15:33 libglib-2.0.so.0
-rw-r--r-- 1 joyner joyner  14K 6月   8 15:33 libgmodule-2.0.so.0
-rw-r--r-- 1 joyner joyner 335K 6月   8 15:33 libgobject-2.0.so.0
-rw-r--r-- 1 joyner joyner  60K 6月   8 15:33 libgstapp-1.0.so.0
-rw-r--r-- 1 joyner joyner 466K 6月   8 15:33 libgstaudio-1.0.so.0
-rw-r--r-- 1 joyner joyner 469K 6月   8 15:33 libgstbase-1.0.so.0
-rw-r--r-- 1 joyner joyner 226K 6月   8 15:33 libgstpbutils-1.0.so.0
-rw-r--r-- 1 joyner joyner 1.3M 6月   8 15:33 libgstreamer-1.0.so.0
-rw-r--r-- 1 joyner joyner  55K 6月   8 15:33 libgstriff-1.0.so.0
-rw-r--r-- 1 joyner joyner 237K 6月   8 15:33 libgsttag-1.0.so.0
-rw-r--r-- 1 joyner joyner 610K 6月   8 15:33 libgstvideo-1.0.so.0
-rw-r--r-- 1 joyner joyner 311K 6月   8 15:33 libjasper.so.1
-rw-r--r-- 1 joyner joyner  57K 6月   8 15:33 libjbig.so.0
-rw-r--r-- 1 joyner joyner 415K 6月   8 15:33 libjpeg.so.8
-rw-r--r-- 1 joyner joyner 151K 6月   8 15:33 liblzma.so.5
-rw-r--r-- 1 joyner joyner 1.7M 6月   8 15:33 libm.so.6
-rwxr-xr-x 1 joyner joyner 486K 6月   8 15:33 libnppc.so.10
-rwxr-xr-x 1 joyner joyner  12M 6月   8 15:33 libnppial.so.10
-rwxr-xr-x 1 joyner joyner 3.9M 6月   8 15:33 libnppicc.so.10
-rwxr-xr-x 1 joyner joyner 7.8M 6月   8 15:33 libnppidei.so.10
-rwxr-xr-x 1 joyner joyner  46M 6月   8 15:33 libnppif.so.10
-rwxr-xr-x 1 joyner joyner  25M 6月   8 15:33 libnppig.so.10
-rwxr-xr-x 1 joyner joyner 6.0M 6月   8 15:33 libnppim.so.10
-rwxr-xr-x 1 joyner joyner  18M 6月   8 15:33 libnppist.so.10
-rwxr-xr-x 1 joyner joyner 3.0M 6月   8 15:33 libnppitc.so.10
-rwxr-xr-x 1 joyner joyner 8.4M 6月   8 15:33 libnpps.so.10
-rwxrwxr-x 1 joyner joyner 1.8M 6月   8 15:33 libopencv_calib3d.so.4.1
-rwxrwxr-x 1 joyner joyner  29M 6月   8 15:33 libopencv_core.so.4.1
-rwxrwxr-x 1 joyner joyner 186M 6月   8 15:33 libopencv_cudaarithm.so.4.1
-rwxrwxr-x 1 joyner joyner 810K 6月   8 15:33 libopencv_cudacodec.so.4.1
-rwxrwxr-x 1 joyner joyner 458M 6月   8 15:33 libopencv_cudafilters.so.4.1
-rwxrwxr-x 1 joyner joyner  40M 6月   8 15:33 libopencv_cudaimgproc.so.4.1
-rwxrwxr-x 1 joyner joyner  15M 6月   8 15:33 libopencv_cudalegacy.so.4.1
-rwxrwxr-x 1 joyner joyner  32M 6月   8 15:33 libopencv_cudaoptflow.so.4.1
-rwxrwxr-x 1 joyner joyner  67M 6月   8 15:33 libopencv_cudawarping.so.4.1
-rwxrwxr-x 1 joyner joyner 975K 6月   8 15:33 libopencv_features2d.so.4.1
-rwxrwxr-x 1 joyner joyner 460K 6月   8 15:33 libopencv_flann.so.4.1
-rwxrwxr-x 1 joyner joyner 8.4M 6月   8 15:33 libopencv_imgcodecs.so.4.1
-rwxrwxr-x 1 joyner joyner  41M 6月   8 15:33 libopencv_imgproc.so.4.1
-rwxrwxr-x 1 joyner joyner 491K 6月   8 15:33 libopencv_objdetect.so.4.1
-rwxrwxr-x 1 joyner joyner 415K 6月   8 15:33 libopencv_videoio.so.4.1
-rw-r--r-- 1 joyner joyner 497K 6月   8 15:33 liborc-0.4.so.0
-rw-r--r-- 1 joyner joyner 454K 6月   8 15:33 libpcre.so.3
-rw-r--r-- 1 joyner joyner 198K 6月   8 15:33 libpng16.so.16
-rwxr-xr-x 1 joyner joyner 142K 6月   8 15:33 libpthread.so.0
-rw-r--r-- 1 joyner joyner  59K 6月   8 15:33 libraw1394.so.11
-rw-r--r-- 1 joyner joyner  31K 6月   8 15:33 librt.so.1
-rw-r--r-- 1 joyner joyner 1.6M 6月   8 15:33 libstdc++.so.6
-rwxr-xr-x 1 joyner joyner 115K 6月   8 15:33 libswresample.so.3
-rwxr-xr-x 1 joyner joyner 523K 6月   8 15:33 libswscale.so.5
-rw-r--r-- 1 joyner joyner 230K 6月   8 15:33 libtbb.so.2
-rw-r--r-- 1 joyner joyner 475K 6月   8 15:33 libtiff.so.5
-rw-r--r-- 1 joyner joyner 119K 6月   8 15:33 libudev.so.1
-rw-r--r-- 1 joyner joyner  95K 6月   8 15:33 libusb-1.0.so.0
-rw-r--r-- 1 joyner joyner  79K 6月   8 15:33 libzip.so.4
-rwxr-xr-x 1 joyner joyner 120K 6月   8 15:33 libz.so.1

http://www.ppmy.cn/news/1557235.html

相关文章

lua dofile 传参数

cat 1.lua arg[1] 111 arg[2] 222 dofile(./2.lua) cat 2.lua print("First argument is: " .. arg[1]) print("Second argument is: " .. arg[2]) 执行 lua 1.lua,结果为: First argument is: 111 Second argument is: 222 l…

kubeadm_k8s_v1.31高可用部署教程

kubeadm_k8s_v1.31高可用部署教程 实验环境部署拓扑图**部署署架构****Load Balance****Control plane node****Worker node****资源分配(8台虚拟机)**集群列表 前置准备关闭swap开启ipv4转发更多设置 1、Verify the MAC address and product_uuid are u…

STM32相关知识及其创建工程

STM32 管脚 相关部件 基本部件: GPIO输入输出,外部中断,定时器,串口中断 基本外设接口: SPI,IIC,WDG,ADC/DAC,这些外设接口功能原理对每个芯片几乎都是一样 高级功能:RTOS,STM32CubeMx,HAL库LWP网络通信&a…

杂七杂八的网络安全知识

一、信息安全概述 1.信息与信息安全 信息与信息技术 信息奠基人:香农:信息是用来消除随机不确定性的东西 信息的定义:信息是有意义的数据,是一种要适当保护的资产。数据经过加工处理之后,就成为信息。而信息需要经…

门户系统需要压测吗?以及门户系统如何压力测试?

一、门户系统为什么要进行压力测试? 首先一点要明确一下,统一门户上线以后,将是所有应用系统的入口,对应门户稳定性要求较高,门户实现了统一入口和统一认证,系统宕机将影响其他系统使用。一般部署架构要求…

JS使用random随机数实现简单的四则算数验证

1.效果图 2.代码实现 index.html <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</ti…

【AIGC安全】CCF-CV企业交流会直播回顾:探寻AI安全治理,共筑可信AI未来

文章目录 一、活动背景&#xff1a;AI技术快速发展与安全治理需求迫切二、论坛内容金耀辉&#xff1a;智能共生时代&#xff1a;平衡生成式AI的创新与风险何延哲&#xff1a;人工智能安全检测评估的逻辑和要点谢洪涛&#xff1a;面向特定人物深度伪造视频的主动防御与被动检测技…

《探秘 QT 5.14.1 类库的奇妙世界》

《探秘 QT 5.14.1 类库的奇妙世界》 一、QT 5.14.1 类库简介1.1 跨平台特性1.2 整体框架构成 二、核心特点剖析2.1 元对象系统2.2 信号与槽的关联方式2.3 全局定义2.3.1 数据类型定义2.3.2 函数2.3.3 宏定义 三、常用类库功能展示3.1 QWidget 类库3.2 其他重要类库&#xff08;…