一、需要用到的hw.cpp hw.h funtest.cpp funtest.h makefile 几个测试文件
1、hw.cpp代码如下:
#include "hw.h" #include "funtest.h" using namespace std; using namespace boost; int main() { timer t; { int i=1; } auto i="abc"; cout<<i<<endl; cout<<"endl"<<endl; cout<<"abcdefj"<<endl; cout << "最大处理时间:" << t.elapsed_max() / 3600 << " h" << endl; cout << "最小处理时间:" << t.elapsed_min() << " s" << endl; cout << "逝去时间:" << t.elapsed() << " s" << endl; cout<<"每行需要一个tab键"<<endl; funtest::testa test1; test1.testafun(); }
2、hw.h代码如下:
#ifndef __HW_H__ #define __HW_H__ #include <iostream> #include <boost/timer.hpp> #include <boost/progress.hpp> #endif
3、funtest.cpp代码如下:
#include "funtest.h" using namespace std; namespace funtest { testa::testa() { cout<<"testa()"<<endl; } testa::~testa() { cout<<"~testa()"<<endl; } void testa::testafun() { cout<<"testa::testafun()"<<endl; } }
4、funtest.h代码如下:
#ifndef __FUNTEST__H__ #define __FUNTEST__H__ #include <iostream> namespace funtest { class testa { public: testa(); ~testa(); void testafun(); }; } #endif
二、makefile的编写以及使用示例
1、makefile代码如下:
#---------------------------------------------------------- #makefile helloworld测试用例 # # # # #----------------------------------------------------------- ggg=g++49 exe=helloworld #所有的.o文件写在这里 obj = hw.o funtest.o #所要关联的cpp文件写在这里 cpp = hw.cpp funtest.cpp $(exe):$(obj) @echo "链接开始................" $(ggg) -o $(exe) $(obj) hw.o : $(cpp) @echo "编译开始................" $(ggg) -std=c++11 -c $(cpp) .PHONY : clean delete all: @echo "开始make all..........." clean: @echo "开始清理................" -rm -rf $(obj) $(exe) delete: @echo "delete.................." pwd
2、使用方法linux简单示例。
[mythcpp@localhost src]$ make clean
开始清理................
rm -rf hw.o funtest.o helloworld
[mythcpp@localhost src]$ make
编译开始................
g++49 -std=c++11 -c hw.cpp funtest.cpp
链接开始................
g++49 -o helloworld hw.o funtest.o
[mythcpp@localhost src]$ make all
开始make all...........
[mythcpp@localhost src]$ make delete
delete..................
pwd
/home/mythcpp/src