实践准备:
包含流程图中的四个绿色框中的文件,实现打印“hello jack”。
绿色框是自己创建的输入文件
蓝色框为生成文件
创建一个test文件,在test文件目录中创建myFunc.h,main.cpp,myFunc.cpp和README.md源文件。
编写myFunc.h中的内容:
vim myFunc.h
#ifndef MYFUNC_H_
#define MYFUNC_H_
bool sayhello();
#endif
编写myFunc.cpp中的内容:
vim myFunc.cpp
#include "myFunc.h"
#include<iostream>
using namespace std;
bool sayhello(){
cout << "hello jack" <<endl;
return true;
}
编写main.cpp中的内容:
vim mian.cpp
#include<cstdlib>
#include"myFunc.h"
int main(){
if(sayhello())
{
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
创建shell脚本 compile.sh:
//创建shell脚本 通过g++编译main.cpp 和 myFunc.cpp 但不链接
vim compile.sh
chmod +x compile.sh //文件赋予权限
./compile.sh //运行文件(编译.cpp)
g++ main.cpp -o main.o -c
g++ myFunc.cpp -o myFunc.o -c
创建链接脚本:
vim link.sh //创建链接脚本
chmod +x link.sh //赋予文件权限
./link.sh //执行shell脚本
g++ main.o myFunc.o -o main
压缩打包文件:
vim zip_release.sh //压缩打包
chmod +x zip_release.sh //文件权限
./zip_release.sh //执行命令
zip release.zip main README.md //README.md中途添加的文件
执行结果: