目标文件和linux或unix中的a.out文件有什么区别? [英] What is the difference between object file and the a.out file in the linux or unix?

查看:303
本文介绍了目标文件和linux或unix中的a.out文件有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用C学习Linux上的编程,我发现在使用命令gcc xyz.c编译源代码文件即.xyz.c时,我们得到一个可执行文件a.out,它具有等效的十六进制代码在里面,这是可以理解的cpu。



这里是我的疑惑

1. -E是什么意思, - S和-c

2.当尝试使用命令gcc xyz.c直接编译时,它会创建一个名为a.out的可执行文件,其中包含等效的十六进制代码,那么a.out之间的区别是什么和.o扩展名文件。

3. linux commnand中-o的确切含义



我有什么尝试过:



但是当我尝试这个程序来查找并观察编译过程中发生的事情时

step 1:gcc -E xyz.c -o xyz.i

它创建一个.i扩展文件,其中包含扩展的源代码。

第2步:gcc -S xyz.i -o xyz.s

它会创建一个.s扩展文件,该文件具有等效的汇编代码。

步骤3:gcc -c xyz.c -o xyz .o

它创建一个目标文件,其具有可由cpu理解的等效十六进制

I have just started learning programming on Linux using C, I have found that on compiling the source code file i.e.., xyz.c using the command gcc xyz.c we get an executable file a.out which has an equivalent hex code in it, and which is understandable by cpu.

here are my doubts
1. what is the meaning of -E, -S and -c
2. when try compiling directly using command gcc xyz.c it creates an executable file named a.out which has equivalent hex code in it, so what is the difference between a.out and .o extension file.
3. what is the exact meaning of -o in the linux commnand

What I have tried:

but when I have tried this procedure to find and observe what is happening in the procedure of compilation
step 1: gcc -E xyz.c -o xyz.i
its creates an .i extension file which has an expanded source code.
step 2: gcc -S xyz.i -o xyz.s
its creates an .s extension file which has an equivalent assembly code.
step 3: gcc -c xyz.c -o xyz.o
its creates an object file which has an equivalent hex understandable by the cpu

推荐答案

创建可执行程序的过程包括:两步:

The process of creating an executable program consists of two steps:


  1. 编译创建目标文件的源文件

  2. 链接目标文件和可选库,用于创建可执行文件



这需要两个工具:编译器和链接器。

GCC是两者,传递的命令行选项指定应该做什么。



-c 选项告诉GCC编译选项后指定的文件。默认情况下,将生成一个具有相同名称但 .o 扩展名的目标文件。



-E -S 选项将开始编译,但在特定处理步骤停止并生成相应类型的输出文件。 br $>


-o 选项指定输出文件名并覆盖默认值(< source-name> ; .o 编译时, a.out 链接时)。



仅使用源文件名调用GCC是一种特殊情况:

它将编译源文件(生成目标文件),链接用于创建可执行文件( a.out )的目标文件,并删除目标文件。



有关所有选项的概述,请参阅< a href =https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html>使用GNU编译器集合(GCC):选项摘要 [ ^ ]。


This requires two tools: A compiler and a linker.
The GCC is both and the passed command line options specify what should be done.

The -c option tells the GCC to compile the file specified after the option. By default an object file with the same name but the .o extensions will be generated.

The -E and -S options will start compilation but stop at specific processing steps and generate an output file of the appropriate type.

The -o option specifies the output file name and overrides the default (<source-name>.o when compiling, a.out when linking).

Invoking GCC with source file names only is a special case:
It will compile the source files (generate object files), link the object files to create an executable file (a.out), and deletes the object files.

For an overview of all options see Using the GNU Compiler Collection (GCC): Option Summary[^].


这篇关于目标文件和linux或unix中的a.out文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆