博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简单编写makefile文件,实现GCC4.9编译项目,增加boost库測试等等。。
阅读量:6970 次
发布时间:2019-06-27

本文共 2373 字,大约阅读时间需要 7 分钟。

一、须要用到的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<<

2、hw.h代码例如以下:

#ifndef __HW_H__#define __HW_H__#include 
#include
#include
#endif

3、funtest.cpp代码例如以下:

#include "funtest.h"using namespace std;namespace funtest{testa::testa(){  cout<<"testa()"<

4、funtest.h代码例如以下:

#ifndef __FUNTEST__H__#define __FUNTEST__H__#include 
namespace funtest{ class testa { public: testa(); ~testa(); void testafun(); };}#endif

二、makefile的编写以及使用演示样例

1、makefile代码例如以下:

#----------------------------------------------------------#makefile helloworld測试用例#####-----------------------------------------------------------ggg=g++49exe=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 deleteall:        @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

3、程序输出演示样例:
[mythcpp@localhost src]$ ./helloworld
abc
endl
abcdefj
最大处理时间:2.56205e+09 h
最小处理时间:1e-06 s
逝去时间:0 s
每行须要一个tab键
testa()
testa::testafun()
~testa()
[mythcpp@localhost src]$
三、须要注意的几点
1、g++49是g++4.9版本号的g++
命令行演示样例:
[mythcpp@localhost src]$ ll /usr/bin/g++49
lrwxrwxrwx. 1 root root 23 May  8 05:05 /usr/bin/g++49 -> /home/gcc-4.9.0/bin/g++
[mythcpp@localhost src]$ type g++49
g++49 is /usr/bin/g++49
2、makefile以tab为间格。不要以空格開始,会报错的。

3、echo 要写在lable以下。如:
$(exe):$(obj)
        @echo "链接開始................"
        $(ggg) -o $(exe) $(obj)
4、makefile文件里的all clean delete 等等伪标签能够自行实现功能命令。
这里最主要是使用make 和make clean两条命令
5、关于makefile的具体编写请百度,谷歌。此文档仅仅适用入门。


转载地址:http://toasl.baihongyu.com/

你可能感兴趣的文章
linux的一些软件基本安装
查看>>
泛型中的类型约束和类型推断
查看>>
sqlserver修改表主键自增
查看>>
SpringBoot系列: Java应用程序传参和SpringBoot参数文件
查看>>
logback的简单配置
查看>>
php实现 字符串分割
查看>>
几何画板如何添加按钮
查看>>
guava快速入门
查看>>
cratedb geo 查询
查看>>
Nginx+Tomcat+Memcached部署
查看>>
内存卡误删数据恢复方法揭密
查看>>
保护REST API/Web服务的最佳实践
查看>>
svn和git的区别及适用场景
查看>>
Ant + ivy的安装
查看>>
用Go编写的本地文件服务器
查看>>
[Angular] Expose Angular Component Logic Using State Reducers
查看>>
模式的分类
查看>>
rocketmq 源码
查看>>
spring cloud: Hystrix(六):feign的注解@FeignClient:fallbackFactory(类似于断容器)与fallback方法...
查看>>
每周分享第2期
查看>>