例子:优化
pintA.hcode
#ifndef __PRINTA_H_ #define __PRINTA_H_ void printA(); #endif
printA.cpp开发
#include "printA.h" #include <stdio.h> void printA() { printf("I am A.\n"); }
printB.hget
#ifndef __PRINTB_H_ #define __PRINTB_H_ void printB(); #endif
printB.cppio
#include "printB.h" #include <stdio.h> void printB() { printf("You are B.\n"); }
语法:编译
g++ 选项 source -o target
预处理:class
g++ -E printA.cpp -o printA.i g++ -E printB.cpp -o printB.i
编译:后台
g++ -S printA.i -o printA.s g++ -S printB.i -o printB.s
汇编:gcc
g++ -c printA.s -o printA.o g++ -c printB.s -o printB.o
连接:语法
g++ main.cpp printA.o printB.o -o main
运行
./main
输出结果:
I am A.
You are B.
参考:《后台开发核心技术与应用实践》