Windows中.lib的格式是什么?

wam*_*amp 6 portable-executable

AFAIK .dllPE格式,那怎么.lib办?

Pre*_*gha 5

我一直认为它们是COFF格式

有关详细信息,请参见此处:http : //support.microsoft.com/? id= 121460 存档

通用目标文件格式 (COFF)

文章 ID:Q121460
创建日期:05-OCT-1994
修订日期:12-OCT-1994

本文中的信息适用于:

  • Microsoft Windows NT 操作系统版本 3.1
  • Microsoft Windows NT 高级服务器 3.1 版
  • Microsoft Windows NT 工作站版本 3.5
  • Microsoft Windows NT 服务器 3.5 版

概括

Windows NT 对可执行(图像)文件和目标文件使用一种特殊的格式。这些文件中使用的格式称为可移植可执行文件 (PE) 或通用对象文件格式 (COFF) 文件。Portable Executable 这个名称指的是可执行文件可以在多个平台上运行这一事实。本文详细介绍了PE/COFF文件格式的内部特征及其参数。

更多信息

PE/COFF 文件头由 MS-DOS 存根、文件签名、COFF 头和可选头组成。目标文件只包含 COFF 头,而图像文件包含上述所有头。这些头文件中最重要的是 COFF 头文件。下表描述了存储在 COFF 头中的信息。

Offset Size Field               Description

0       2   Machine             Number identifying type of target machine.
2       2   Number of Sections  Number of sections; indicates size of the
                                Section Table, which immediately follows
                                the headers.
4       4   Time/Date Stamp     Time and date the file was created.
8       4   Pointer to Symbol   Offset, within the COFF file, of the symbol
            Table               table.
12      4   Number of Symbols   Number of entries in the symbol table.
                                This data can be used in locating the
                                string table, which immediately follows
                                the symbol table.
16      2   Optional Header     Size of the optional header, which is
            Size                included for executable files but not
                                object files. An object file should have a
                                value of 0 here.
18      2   Characteristics     Flags indicating attributes of the file.
Run Code Online (Sandbox Code Playgroud)

Windows NT 软件开发工具包 (SDK) 提供了一个名为 DUMPBIN 的实用程序。DUMPBIN 是一个 32 位工具,用于显示有关 32 位通用对象文件格式 (COFF) 二进制文件的信息。DUMPBIN 只能从命令提示符运行。您可以使用 DUMPBIN 检查以下类型的 COFF 文件:对象文件、COFF 对象的标准库、可执行文件和动态链接库 (DLL) 文件。

要运行 DUMPBIN,请使用以下语法:

DUMPBIN [options] [files]
Run Code Online (Sandbox Code Playgroud)

以下是 DUMPBIN 的选项参数和定义:

    /ALL
    /ARCHIVEMEMBERS
    /DISASM
    /EXPORTS
    /HEADERS
    /IMPORTS
    /LINENUMBERS
    /LINKERMEMBER[:{1|2}]
    /OUT:filename
    /PDATA
    /RAWDATA[:{NONE|BYTES|SHORTS|LONGS}[,#]]
    /RELOCATIONS
    /SECTION:name
    /SUMMARY
    /SYMBOLS

Options          Definition

/ALL             Setting this option causes DUMPBIN to display all
                 available information except code disassembly.

/ARCHIVEMEMBERS  Setting this option causes DUMPBIN to display minimal
                 information about member objects in a library.

/DISASM          Setting this option causes DUMPBIN to show disassembly
                 of code sections, using symbols if present in the file.

/EXPORTS         This option causes DUMPBIN to list all definitions
                 exported from an executable file or DLL.

/HEADERS         Setting this option causes DUMPBIN to display the file
                 header and the header for each section. When used with a
                 library, displays the header for each member object.

/IMPORTS         This option causes DUMPBIN to list all definitions
                 imported to an executable file or DLL.

/LINENUMBERS     Setting this option causes DUMPBIN to show COFF line
                 numbers. Line numbers exist in an object file if it was
                 compiled with /Zi. An executable file or DLL contains
                 COFF line numbers if it was linked with /DEBUG and
                 /DEBUGTYPE:COFF option.

/LINKERMEMBER [[:{1|2}]]
                 Setting this option causes DUMPBIN to list public symbols
                 defined in a library. Specify the 1 argument to display
                 symbols in object order, along with their offsets. Specify
                 the 2 argument to display offsets and index numbers of
                 objects, then list the symbols in alphabetical order along
                 with the object index for each. To get both outputs,
                 specify /LINKERMEMBER without the number argument.

/OUT:<filename>  This option specifies a filename for the output.
/RAWDATA [[:{BYTES|SHORTS|LONGS|NONE}[[,number]]]]
                 Setting this option causes DUMPBIN to display the raw
                 contents of each section in the file. The arguments
                 control the format of the display, as follows:
      Argument - Result
      BYTES    - The default. Contents are displayed in hexadecimal bytes,
                 and also as ASCII if they have a printed representation.
      SHORTS   - Contents are displayed in hexadecimal words.
      LONGS    - Contents are displayed in hexadecimal longwords.
      NONE     - Raw data is suppressed. This is useful to control the
                 output of /ALL.
      number   - Displayed lines are set to a width that holds number
                 values per line.

/RELOCATIONS     Setting this option causes DUMPBIN to display any
                 relocations in the object or image.

/SECTION: <section>
              This option restricts the output to information on the
              specified section.

/SUMMARY      Setting this option causes DUMPBIN to display minimal
              information about sections, including total size. This
              option is the default if no other option is specified
              in a DUMPBIN command.

/SYMBOLS      Setting this option causes DUMPBIN to display the COFF symbol
              table. Symbol tables exist in all object files. A COFF symbol
              table appears in an image file only if it is linked with
              /DEBUG /DEBUGTYPE:COFF
Run Code Online (Sandbox Code Playgroud)

替代文字


jlg*_*ego 5

有2种扩展名为.lib的文件:

  1. 静态库(用于静态链接)
  2. 导入库(用于动态链接)

两者都是COFF文件的存档。该档案的格式为“ ar档案”。

Unix(cygwin / mingw)命令ar可以像tar命令一样解析此文件。

如果要查看.lib中的存档文件,可以执行以下操作:

ar tv <name>.lib
Run Code Online (Sandbox Code Playgroud)

通常,如果看到.obj文件,则意味着它是一个静态库。如果您看到.dll,则它是一个导入库。