背景
如何将程序依赖的动态库拷贝到指定的目录?
例子
- 通过LDD查看依赖的动态库。
bash
$ ldd extract_gpu
linux-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)
- 写一个SHELL脚本,自动拷贝依赖的动态库。
vi release.sh
#!/bin/bash
deplist=$( ldd $1 | awk '{if (match($3,"/")){ print $3}}' )
cp -L -n $deplist $2
-L 表示拷贝文件(如果是软链,会拷贝到最终的文件)。
-n 表示不覆盖已有文件。
-
创建目标目录
mkdir release
-
将postgres依赖的动态库拷贝到目标目录
bash release.sh extract_gpu ./release/
bash
ll ./release
total 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