# 0.3 c 语言编译过程

来自: <https://www.cnblogs.com/CarpenterLee/p/5994681.html>

<figure><img src="https://labspc.com/wp-content/uploads/2024/01/1705507499-word-image-250-1.png" alt=""><figcaption></figcaption></figure>

预处理 preprocessor gcc- E 是把 .c 源代码处理成 .i

编译 compilation gcc -S 处理成 .s 特定的汇编代码

汇编 assemble gcc -c 把 .s 文件处理 .o

.o 是一个二进制文件

.out 是一个可执行文件

从 .o 到 .out 的过程就是一个链接 linking

~~2023-08-31~~

{% code title="0.3 main.c" lineNumbers="true" %}

```c
//
//  main.c
//  kr-c
//
//  Created by labspc on 2023/8/23.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    printf("Hello, World!\n");
    return 0;
}

```

{% endcode %}

{% code lineNumbers="true" %}

```
// Some code
gcc -E main.c -o main.i

gcc -S main.c -o main.s

gcc main.o -o main.out  直接链接 .o文件>>.out

gcc -c main.s -o main.o 汇编的过程 

gcc main.o -o main.out 链接

```

{% endcode %}

{% code lineNumbers="true" %}

```
// Some code
gcc main.c
./a.out

```

{% endcode %}

a.out 和 main.out 是一样的。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://labspc.gitbook.io/cnippets/readme/0.3-c-yu-yan-bian-yi-guo-cheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
