c++可执行文件产生过程

https://blog.csdn.net/qq_34799070/article/details/125472381


#ifndef TEST
#define TEST

#include <iostream>
using namespace std;

void test()
{
    cout << "hello word" << endl;

}

#endif
#include <iostream>
#include <mytest.h>
using namespace std;

// https://blog.csdn.net/chen1083376511/article/details/114447485
// g++ -I .\include\ -Wall -std=c++11 .\main.cpp -o .\output\main.exe

// 1. 预处理--宏展开,头文件包含:g++ -I .\include\ -Wall -std=c++11 -E .\main.cpp -o .\output\main.i
// 2. 编译--生成汇编语句代码:g++ -S .\output\main.i -o .\output\main.s 
// 3. 汇编--生成机器语言代码:g++ -c .\output\main.s -o .\output\main.o
// 4. 链接--生成可执行稳健:g++ .\output\main.o -o .\output\main.exe
int main()
{
    test();
    return 0;
}

生成一个C++程序共有三个步骤:

  1. 预处理:代码在预处理器中运行,预处理器会识别代码中的元信息。

  2. 编译:代码被编译或转换为计算机可以识别的目标文件。

  3. 链接:独立的目标文件链接在一起变成一个应用程序。

posted @ 2022-09-28 17:20  douzujun  阅读(29)  评论(0编辑  收藏  举报