image.png

1 预处理-Pre-Processing

  1. # -E 选项指示编译器仅对输入文件进行预处理
  2. # 产生的是.i文件
  3. g++ -E test.cpp -o test.i //.i文件

2 编绎-Compiling

# -S 编译选项告诉 g++ 在为 C++ 代码产生了汇编语言文件后停止编译
# g++ 产生的汇编语言文件的缺省扩展名是 .s
g++  -S test.i  -o  test.s

3 汇编-Assembling

# -c 选项告诉 g++ 仅把源代码编译为机器语言的目标代码
# 缺省时 g++ 建立的目标代码文件有一个 .o 的扩展名。
g++  -c test.s  -o test.o

4 链接-Linking

# -o 编译选项来为将产生的可执行文件用指定的文件名
g++ test.o  -o test

5 一步搞定

g++ test.cpp -o test

准备cpp文件

#include <stdio.h>

int main(){
    printf("Hello C++");
    return 0;
}