程序执行的过程
检查程序的语法错误
预处理
进行简单的替换。
//程序名称:test.cpp
#include<iostream>
#define hello "六六六"
int main(){
std::cout<<hello<<std::endl;
}
此命令将 test.cpp文件进行预编译,编译的结果放在了test.txt文件中。
如果没有 ">test.txt" 命令,则预编译的结果会直接打印在屏幕上。
编译
linux中默认生成.o文件;windows中生成.exe文件。
链接
把多个目标文件链接成可执行文件
//程序名称:main.c #include <stdio.h> #include "add.h" #include "sub.h" int main(){ int a,b; printf("请输入a和b:"); scanf("%d%d",&a,&b); printf("%d + %d = %d\n",a,b,add(a,b)); printf("%d - %d = %d\n",a,b,sub(a,b)); return 0; }
//程序名称:add.h int add(int,int);
//程序名称:add.c int add(int a,int b){ return a+b; }
//程序名称:sub.h int sub(int,int);
//程序名称:sub.c int sub(int a,int b){ return a-b; }
gcc *.o -o test.exe
//将所有.o文件链接为一个.exe文件
制作makefile文件
/*
目的:依赖
通过依赖生成目的的语句
*/
demo.exe:main.o add.o sub.o