next up previous contents
Next: 管理函式庫實例 Up: Makefile 函式庫 Previous: ldconfig 函式庫工具   Contents

建立函式庫工具

  1. ar 輔助說明
    [dywang@dywmac ~]$ ar --help
    Usage: ar [emulation options] [-]{dmpqrstx}[abcDfilMNoPsSTuvV] [--plugin <name>] [member-name] [count] archive-file file...
           ar -M [<mri-script]
     commands:
      d            - delete file(s) from the archive
      m[ab]        - move file(s) in the archive
      p            - print file(s) found in the archive
      q[f]         - quick append file(s) to the archive
      r[ab][f][u]  - replace existing or insert new file(s) into the archive
      s            - act as ranlib
      t            - display contents of archive
      x[o]         - extract file(s) from the archive
     command specific modifiers:
      [a]          - put file(s) after [member-name]
      [b]          - put file(s) before [member-name] (same as [i])
      [D]          - use zero for timestamps and uids/gids
      [U]          - use actual timestamps and uids/gids (default)
      [N]          - use instance [count] of name
      [f]          - truncate inserted file names
      [P]          - use full path names when matching
      [o]          - preserve original dates
      [u]          - only replace files that are newer than current archive contents
     generic modifiers:
      [c]          - do not warn if the library had to be created
      [s]          - create an archive index (cf. ranlib)
      [S]          - do not build a symbol table
      [T]          - make a thin archive
      [v]          - be verbose
      [V]          - display the version number
      @<file>      - read options from <file>
      --target=BFDNAME - specify the target object format as BFDNAME
     optional:
      --plugin <p> - load the specified plugin
     emulation options: 
      No emulation specific options
    ar: supported targets: elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
    Report bugs to <http://bugzilla.redhat.com/bugzilla/>
    
  2. ar 選項簡易說明
    r :在函式庫中插入目標檔。當插入的目標檔名已在庫中存在,則替換。
    v :顯示執行操作選項的附加信息。
    
  3. nm 輔助說明
    [dywang@dywmac ~]$ nm --help
    Usage: nm [option(s)] [file(s)]
     List symbols in [file(s)] (a.out by default).
     The options are:
      -a, --debug-syms       Display debugger-only symbols
      -A, --print-file-name  Print name of the input file before every symbol
      -B                     Same as --format=bsd
      -C, --demangle[=STYLE] Decode low-level symbol names into user-level names
                              The STYLE, if specified, can be `auto' (the default),
                              `gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'
                              or `gnat'
          --no-demangle      Do not demangle low-level symbol names
      -D, --dynamic          Display dynamic symbols instead of normal symbols
          --defined-only     Display only defined symbols
      -e                     (ignored)
      -f, --format=FORMAT    Use the output format FORMAT.  FORMAT can be `bsd',
                               `sysv' or `posix'.  The default is `bsd'
      -g, --extern-only      Display only external symbols
      -l, --line-numbers     Use debugging information to find a filename and
                               line number for each symbol
      -n, --numeric-sort     Sort symbols numerically by address
      -o                     Same as -A
      -p, --no-sort          Do not sort the symbols
      -P, --portability      Same as --format=posix
      -r, --reverse-sort     Reverse the sense of the sort
          --plugin NAME      Load the specified plugin
      -S, --print-size       Print size of defined symbols
      -s, --print-armap      Include index for symbols from archive members
          --size-sort        Sort symbols by size
          --special-syms     Include special symbols in the output
          --synthetic        Display synthetic symbols as well
      -t, --radix=RADIX      Use RADIX for printing symbol values
          --target=BFDNAME   Specify the target object format as BFDNAME
      -u, --undefined-only   Display only undefined symbols
      -X 32_64               (ignored)
      @FILE                  Read options from FILE
      -h, --help             Display this information
      -V, --version          Display this program's version number
    
    nm: supported targets: elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
    Report bugs to <http://bugzilla.redhat.com/bugzilla/>.
    
  4. ar 將 2.o 3.o 兩個目標檔案組合成一個函式庫檔案 mylib.a。
    [dywang@dyw219 make1]$ ar rv mylib.a 2.o 3.o
    ar: creating mylib.a
    a - 2.o
    a - 3.o
    
  5. nm:查看目標檔庫檔案 mylib.a 的內容,包含了 2.o 及 3.o。
    [dywang@dyw219 make1]$ nm mylib.a 
    
    2.o:
    0000000000000000 T function_two
                     U puts
    
    3.o:
    0000000000000000 T function_three
    



De-Yu Wang 2019-08-12