// ” “表示首先在源文件目录下查找
// include 内容在预处理时把头文件里定义内容复制到当前行,进行宏定义的替换, 在编译阶段检查语法错误,生成文本文件
//汇编后生成目标文件 .o, 链接阶段分为静态链接和动态链接, 静态链接在编译时把库文件中全部文件加入到可执行文件中(后缀名.a), 动态链接字执行时加载,后缀名.so
#include <iostream>
#include "f.h"
using namespace std;
int main(){
cout<<myplus(2, 4)<<endl<<myminus(2, 4)<<endl;
return 0;
}
f.h
// 头文件中主要包含C库头文件 类型 结构体定义 函数声明
int myplus(int a, int b);
int myminus(int a, int b);
f1.cpp
#include "f.h"
int myplus(int a, int b){
return a+b;
}
f2.cpp
#include "f.h"
int myminus(int a, int b){
return a-b;
}
Makefile
#target: depencies
# command
# makefile 按依赖项编译,想编译多个的话在all里面指定所有要编译的
CC = g++
all: hello
hello: main.o f1.o f2.o
$(CC) main.o f1.o f2.o -o main
f1.o: f1.cpp
$(CC) -c f1.cpp
f2.o: f2.cpp
$(CC) -c f2.cpp
clear:
rm *.o main