概述
1. 场景
1.1 用C++写的程序,总是涉及到动态链接库的编译与使用。比如自己写的文件打包成了动态库,这个动态库又链接了其他动态库。这样在给别人的时候,需要给那些库呢?只是给自己编译好的吗?还是其他
2. 解决方案
ldd
在ubuntu上可以用用 ldd
查看一个文件的动态链接库依赖。这样就看可以一目了然,需要给哪些东西了。
例子
这里以我自己编译的一个 exe 为例:
ldd segDemo
out:
linux-vdso.so.1 (0x00007ffd14b29000)
libmegengine.so => /home/data/CM/8_instance_segmentation/devices/Pspnet_5.1/lib/libmegengine.so (0x00007fb769f38000)
libopencv_highgui.so.3.4 => /usr/local/lib/libopencv_highgui.so.3.4 (0x00007fb769d23000)
libopencv_imgcodecs.so.3.4 => /usr/local/lib/libopencv_imgcodecs.so.3.4 (0x00007fb76973c000)
libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007fb767fd4000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb767bf1000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb7679d9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb7675e8000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb7673c9000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb7671c5000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb766fbd000)
libmynvonnxparser.so => /home/data/CM/8_instance_segmentation/devices/Pspnet_5.1/lib/libmynvonnxparser.so (0x00007fb766c43000)
libmynvonnxparser_runtime.so => /home/data/CM/8_instance_segmentation/devices/Pspnet_5.1/lib/libmynvonnxparser_runtime.so (0x00007fb766952000)
libnvinfer.so.5 => /home/data/CM/profile/TensorRT-5.1.5.0/lib/libnvinfer.so.5 (0x00007fb75dcb5000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb76a1c1000)
libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007fb75d66a000)
libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007fb75d3b5000)
libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007fb75d0a1000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007fb75ce7f000)
libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007fb75cc2c000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fb75c91b000)
libopencv_imgproc.so.3.4 => /usr/local/lib/libopencv_imgproc.so.3.4 (0x00007fb75a04c000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007fb759df3000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007fb759bce000)
libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007fb759959000)
libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007fb759704000)
libIlmImf-2_2.so.22 => /usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22 (0x00007fb759234000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb758e96000)
libcudart.so.10.1 => /usr/local/cuda/lib64/libcudart.so.10.1 (0x00007fb758c1a000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fb7589fd000)
libprotobuf.so.18 => /usr/local/lib/libprotobuf.so.18 (0x00007fb75854d000)
libcudnn.so.7 => /usr/local/cuda/lib64/libcudnn.so.7 (0x00007fb73e903000)
libcublas.so.10 => /usr/lib/x86_64-linux-gnu/libcublas.so.10 (0x00007fb739c49000)
libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007fb739a45000)
libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007fb739838000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fb7394fe000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007fb7392f8000)
libatk-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007fb7390d3000)
libgio-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007fb738d4b000)
libpangoft2-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007fb738b35000)
libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007fb7388e9000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fb7386a6000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007fb73849c000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007fb738299000)
libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007fb738089000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007fb737e7e000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007fb737c74000)
libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007fb737a71000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007fb73786e000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fb73765c000)
libpixman-1.so.0 => /usr/lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007fb7373b4000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fb73710a000)
libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007fb736f06000)
libxcb-render.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007fb736cfc000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fb736ada000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fb7368d2000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fb736662000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fb736440000)
libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007fb736232000)
libHalf.so.12 => /usr/lib/x86_64-linux-gnu/libHalf.so.12 (0x00007fb735fef000)
libIex-2_2.so.12 => /usr/lib/x86_64-linux-gnu/libIex-2_2.so.12 (0x00007fb735dd1000)
libIlmThread-2_2.so.12 => /usr/lib/x86_64-linux-gnu/libIlmThread-2_2.so.12 (0x00007fb735bca000)
libcublasLt.so.10 => /usr/lib/x86_64-linux-gnu/libcublasLt.so.10 (0x00007fb73366a000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fb733448000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fb73322d000)
libharfbuzz.so.0 => /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007fb732fcf000)
libthai.so.0 => /usr/lib/x86_64-linux-gnu/libthai.so.0 (0x00007fb732dc6000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fb732b9d000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fb732999000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fb732793000)
libgraphite2.so.3 => /usr/lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007fb73256d000)
这样就可以看到可以执行文件的依赖了。
问题1:
你已经编译好的可执行文件,别人怎么样可以运行。
解决:
- 别人机子上有可执行文件,所有的动态依赖库,且路径在环境变量中
- 你将可执行文件所依赖的动态库,打包之后同可执行文件一起给用户。用户将可执行文件和动态库放一个目录,就可以执行了。
问题2:
给别demo源码+动态库,别人自己编译时,需要给哪些动态库呢?
解决:
- 同上,将所需要的所有动态库一起给用户
最后
以上就是干净百合为你收集整理的【C++】——动态链接库检查ldd不香吗?的全部内容,希望文章能够帮你解决【C++】——动态链接库检查ldd不香吗?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复