linux c编程之动态库搜索路径和动态库的调试

动态库的搜索路径:
linux c编程之动态库搜索路径和动态库的调试_第1张图片

方法一:(1) 
    把xxx.so 放到/usr/lib或lib中
方法二:(2) 通过设置环境变量方法   绝对路径
    export LD_LIBRARY_PATH= xxx : $LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:xxxx
方法三:(3)/etc/ld.so.conf文件中加入我们生成库的目录
		vim 打开/etc/ld.so.conf,然后在下面加入一行路径代码
		然后通过/sbin/ldconfig  xxx 读取
		ldconfig /etc/ld.so.conf
		ldconfig -v

动态库的调试:
(1)查看动态库的平台架构是否正确

 file  xxxx 
   file /lib/aarch64-linux-gnu/libjpeg.so.62.3.0
   /lib/aarch64-linux-gnu/libjpeg.so.62.3.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, stripped

(2)查看应用程序或者库的组成

  ldd  xxx 
   显示glibc 版本
   ldd --version
	ldd  2.35
	
	ldd /lib/aarch64-linux-gnu/libjpeg.so.62.3.0
	linux-vdso.so.1 (0x0000007fb4800000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fb45b0000)
	/lib/ld-linux-aarch64.so.1 (0x0000007fb47c7000)
	
	ldd jpeg
	linux-vdso.so.1 (0x0000007f82928000)
	libjpeg.so.62 => /lib/aarch64-linux-gnu/libjpeg.so.62 (0x0000007f82860000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f826b0000)
	/lib/ld-linux-aarch64.so.1 (0x0000007f828ef000)

(3)显示动态库查找过程
LD_DEBUG=libs ./jpeg

LD_DEBUG=libs ./jpeg
  LD_DEBUG=help date 
	
  libs        display library search paths
  reloc       display relocation processing
  files       display progress for input file
  symbols     display symbol table processing
  bindings    display information about symbol binding
  versions    display version dependencies
  scopes      display scope information
  all         all previous options combined
  statistics  display relocation statistics
  unused      determined unused DSOs
  help        display this help message and exit
  
  LD_DEBUG=libs jpeg
  LD_DEBUG=libs ./jpeg

 LD_DEBUG=libs ./jpeg
      2061:	find library=libjpeg.so.62 [0]; searching
      2061:	 search cache=/etc/ld.so.cache
      2061:	  trying file=/lib/aarch64-linux-gnu/libjpeg.so.62
      2061:	
      2061:	find library=libc.so.6 [0]; searching
      2061:	 search cache=/etc/ld.so.cache
      2061:	  trying file=/lib/aarch64-linux-gnu/libc.so.6
      2061:	
      2061:	
      2061:	calling init: /lib/ld-linux-aarch64.so.1
      2061:	
      2061:	
      2061:	calling init: /lib/aarch64-linux-gnu/libc.so.6
      2061:	
      2061:	
      2061:	calling init: /lib/aarch64-linux-gnu/libjpeg.so.62
      2061:	
      2061:	
      2061:	initialize program: ./jpeg
      2061:	
      2061:	
      2061:	transferring control: ./jpeg
      2061:	
not jpg file./test.jpg
      2061:	
      2061:	calling fini: ./jpeg [0]
      2061:	
      2061:	
      2061:	calling fini: /lib/aarch64-linux-gnu/libjpeg.so.62 [0]
      2061:	

你可能感兴趣的:(#,linux,c语言,开发语言,服务器,ubuntu)