C语言 如何打开 .o 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36002159/
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-09-02 10:22:11  来源:igfitidea点击:

How to open .o file?

cfile-extension

提问by Amit Kumar

After compiling a C program, you get a .o file. I know it's a file consisting of '0's and '1's and if formed after successful compilation of a program. But I want to see what is in the file!

编译一个 C 程序后,你会得到一个 .o 文件。我知道这是一个由“0”和“1”组成的文件,并且是在成功编译程序后形成的。但我想看看文件里有什么!

回答by Hal

you've got a couple of choices here.

你在这里有几个选择。

Firstly (and easiest) is to use something that decodes the file to show you what it is. objdump on linux does this.

首先(也是最简单的)是使用解码文件的东西来显示它是什么。linux 上的 objdump 就是这样做的。

gcc -c test.c

gives you test.o

给你 test.o

objdump -D test.o

will decode the file and show you what's in it on standard output (so pipe it to less or similar) Objdump output shows you the unlinked object file. The addresses aren't valid and have to be fixed up by the linker.
the format is first a line number then some number of bytes that are the cpu instruction, these are shown in hexadecimal.eg 14 means 00010100 next comes the instruction that these byes represent

将解码文件并在标准输出中向您显示其中的内容(因此将其传送到更少或类似的内容) Objdump 输出向您显示未链接的目标文件。地址无效,必须由链接器修复。
格式首先是行号,然后是作为 cpu 指令的一些字节数,这些以十六进制显示。例如 14 表示 00010100 接下来是这些字节表示的指令

   0:   14 00                   adc    ##代码##x0,%al

so above we have line 0 of the function - it's unlinked) 14 00 - these are the bytes they mean add with carry 0 to the al register storing the result in al

所以在上面我们有函数的第 0 行 - 它没有链接)14 00 - 这些是它们的意思的字节加上进位 0 到 al 寄存器,将结果存储在 al 中

Another alternative is to use a hex editor and try and work out what 14 00 means without any assistance.

另一种选择是使用十六进制编辑器,并在没有任何帮助的情况下尝试找出 14 00 的含义。

Good luck.

祝你好运。

回答by Suranjan Daw

You can use hexdumpcommand from the terminal to display the content.

您可以hexdump从终端使用命令来显示内容。

Syntax :$ hexdump <filename>.o

句法 :$ hexdump <filename>.o

It will show you the content in hexadecimalform.

它将以hexadecimal表格形式向您显示内容。

回答by Jonh Doe

just use a hex editor. It Allows you to find data patterns in multi-gigabyte files in seconds. It's powerful. Supports regular expression search across the files. It's handy. Allows you to make file patches in just one click. It's smart. It's flexible. It's efficient.

只需使用十六进制编辑器。它允许您在几秒钟内找到多 GB 文件中的数据模式。它很强大。支持跨文件的正则表达式搜索。它很方便。允许您一键制作文件补丁。它很聪明。它很灵活。这是有效的。