C++ 静态库的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3757108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 13:38:11  来源:igfitidea点击:

Contents of a static library

c++cgccstatic-librariesobject-files

提问by Prasoon Saurav

I have a static library, say mystaticlib.a. I want to see its contents, such as the number of object files inside it.

我有一个静态库,比如mystaticlib.a. 我想查看其内容,例如其中的目标文件数。

How can I do this on gcc?

我怎样才能在 gcc 上做到这一点?

回答by Prasoon Saurav

On gcc, use ar -t.

在 gcc 上,使用ar -t.

-toption of the gnu archiver (ar)writes a table of contents of archive to the standard output. Only the files specified by the file operands shall be included in the written list. If no file operands are specified, all files in archive shall be included in the order of the archive.

-tgnu 归档程序 (ar) 的选项将归档目录写入标准输出。只有文件操作数指定的文件才应包含在写入列表中。如果未指定文件操作数,则归档中的所有文件都应按归档的顺序包含在内。

More info here.

更多信息在这里

回答by Jens Gustedt

You can see the contents (the .o files that went into it) and the defined symbols by using nm. If this contains C++ code you should use the -Coption to demangle the symbol names:

您可以使用 .o 文件查看内容(进入其中的 .o 文件)和定义的符号nm。如果这包含 C++ 代码,您应该使用该-C选项来对符号名称进行解构:

nm -C libschnoeck.a | less

回答by kakyo

On a Mac, simply use

在 Mac 上,只需使用

nm libschnoeck.a | less

There is no -Coption with the Mac version of nm.

-CMac 版 nm没有选项。

回答by Nilesh Kumar

All the answers above are correct. Just I am providing a URL for more information on "nm" command.

以上所有答案都是正确的。我只是提供了一个 URL,以获取有关“nm”命令的更多信息。

You can refer to the below mentioned website.

你可以参考下面提到的网站。

https://www.mkssoftware.com/docs/man1/nm.1.asp

https://www.mkssoftware.com/docs/man1/nm.1.asp

回答by GreenB?rg

It just stumbled over this:

它只是偶然发现了这个:

You can open an archive (.a) with 7zip. Also works for the object files in the archive. Listing all sorts of contents like .text, .bss, .data,etc. with their offset, length, type,... Furthermore its possible to unpack all, using a hex editor or notepad++ to view the contents. I tested this with an archive created with GNUToolsARMEmbedded\2018-q4-major\bin\arm-none-eabi-Toolchain and 7Zip 16.04 (64-bit)

您可以使用 7zip 打开存档 (.a)。也适用于存档中的目标文件。列出各种内容,如.text, .bss, .data,offset, length, type,......此外,可以使用十六进制编辑器或记事本++查看内容来解压缩所有内容。我使用GNUToolsARMEmbedded\2018-q4-major\bin\arm-none-eabi-工具链创建的存档对此进行了测试,并且7Zip 16.04 (64-bit)