• .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

    1. binutils is keg-only, which means it was not symlinked into /usr/local,
    2. because because Apple provides the same tools and binutils is poorly supported on macOS.
    3. If you need to have binutils first in your PATH run:
    4. echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> ~/.bash_profile
    5. For compilers to find binutils you may need to set:
    6. export LDFLAGS="-L/usr/local/opt/binutils/lib"
    7. 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

    结果:

    1. atoi.o:
    2. Load command 0
    3. cmd LC_SEGMENT_64
    4. cmdsize 392
    5. segname
    6. vmaddr 0x0000000000000000
    7. vmsize 0x00000000000000a0
    8. fileoff 552
    9. filesize 160
    10. maxprot 0x00000007
    11. initprot 0x00000007
    12. nsects 4
    13. flags 0x0
    14. Section
    15. sectname __text
    16. segname __TEXT
    17. addr 0x0000000000000000
    18. size 0x000000000000003d
    19. 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

  • 相关阅读:
    【ESP32】VScode + platformIO 环境搭建
    ChatGPT第五讲
    数据分析工具有哪些,哪个好学?
    数据库第七章作业
    六、OpenAI之嵌入式(Embedding)
    这个方法可以实现自动抠图,快来get
    Spring中的循环依赖的解决办法
    LuatOS-SOC接口文档(air780E)--nbiot - NB-IOT操作库
    开源的大模型
    1、如何抓取Modbus TCP/UDP 数据包实战
  • 原文地址:https://blog.csdn.net/huanhuaqian/article/details/126374293