.o .a .lo .la

转载引用: Linux中的动态库和静态库(.a/.la/.so/.o) - findumars - 博客园

  • .o 是目标文件,相当于Windows中的.obj文件
  • .so 为共享库,是shared object,用于动态连接的,和dll差不多
  • .a 为静态库,是好多个.o合在一起,用于静态连接
  • .lo: 使用libtool编译出的目标文件,其实就是在o文件中添加了一些信息
  • .la 为libtool自动生成的一些共享库,vi编辑查看,记录同名动态库和静态库的相关信息
    。可以用如下命令查看*.la文件的格式 
     

工具:libtools 

使用brew update && brew install binutils,然后用greadelfgobjdump

binutils is keg-only, which means it was not symlinked into /usr/local,
because because Apple provides the same tools and binutils is poorly supported on macOS.

If you need to have binutils first in your PATH run:
  echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> ~/.bash_profile

For compilers to find binutils you may need to set:
  export LDFLAGS="-L/usr/local/opt/binutils/lib"
  export CPPFLAGS="-I/usr/local/opt/binutils/include"

>>readelf -h atoi.o
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start

使用 otool 命令查看:

>> otool -l atoi.o

结果:

atoi.o:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 392
  segname
   vmaddr 0x0000000000000000
   vmsize 0x00000000000000a0
  fileoff 552
 filesize 160
  maxprot 0x00000007
 initprot 0x00000007
   nsects 4
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x0000000000000000
      size 0x000000000000003d
    offset 552

>> file atoi.o
atoi.o: Mach-O 64-bit object x86_64

>> otool -L main
main:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)

 >> otool -L atoi.so.1
atoi.so.1:
    atoi.so.1 (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)

>> libtool --mode=compile gcc -c atoi.c
error: /Library/Developer/CommandLineTools/usr/bin/libtool: unknown option character `-' in: --mode=compile

原因:This is because OS X has its own libtool, quite different from GNU's libtool。

解决方案:安装 gnubin 工具,直接brew install libtool* 即可。

>> brew install libtool*

>> libtool --tag=CC  --mode=compile gcc -c atoi.c
libtool: compile:  gcc -c atoi.c  -fno-common -DPIC -o .libs/atoi.o
libtool: compile:  gcc -c atoi.c -o atoi.o >/dev/null 2>&1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值