C/C++(7)Intro to Makefile
2017-01-02 16:08
211 查看
Abstract
This blog will show you how to write a “makefile” file.
1. Concept
A makefile is a file containing a set of directives, directing a complier to link a program in a certain order.
2. An Example
file1.h
file1.cpp
file2.h
file2.cpp
main.cpp
makefile
3. Reference
https://github.com/Canhui/C-Plus-Standard-By-Practice/tree/master/Project_1_Makefile
http://blog.csdn.net/wallwind/article/details/6791505
http://wenku.baidu.com/link?url=P2odKaCA4zRTieikBQoaSD77YBOQTbnG0D3VHxNdTJDTsitCNsKdrZIgxfRfW2vrdpPFhfMuHfWJHfwDPWFrTT-KnXD7GBJBTxYvSxiRDh3
This blog will show you how to write a “makefile” file.
1. Concept
A makefile is a file containing a set of directives, directing a complier to link a program in a certain order.
2. An Example
file1.h
#ifndef file1_h #define file1_h void tool1(char *); void tool1(const char *); #endif
file1.cpp
#include <stdio.h> #include "file1.h" void tool1(char *str){ printf("This is file1 print: %s\n",str); } void tool1(const char *str){ printf("This is file1 print: %s\n",str); }
file2.h
#ifndef file2_h #define file2_h void tool2(char *); void tool2(const char *); #endif
file2.cpp
#include <stdio.h> #include "file2.h" void tool2(char *str){ printf("This is file2 print: %s\n",str); } void tool2(const char *str){ printf("This is file2 print: %s\n",str); }
main.cpp
#include <stdio.h> #include <stdlib.h> #include "file1.h" #include "file2.h" int main(){ char str1[] = "hello"; tool1(str1); const char str1_c[] = "hello"; tool1(str1_c); char str2[] = "hello"; tool2(str2); const char str2_c[] = "hello"; tool2(str2_c); }
makefile
CC := g++ CFLAGS := -g TARGET := target SRCS := $(wildcard *.cpp) OBJS := $(patsubst %cpp,%o,$(SRCS)) all:$(TARGET) clean %.o:%.cpp $(CC) $(CFLAGS) -c $< $(TARGET):$(OBJS) $(CC) $(CFLAGS) -o $@ $^ clean: rm -rf *.o
3. Reference
https://github.com/Canhui/C-Plus-Standard-By-Practice/tree/master/Project_1_Makefile
http://blog.csdn.net/wallwind/article/details/6791505
http://wenku.baidu.com/link?url=P2odKaCA4zRTieikBQoaSD77YBOQTbnG0D3VHxNdTJDTsitCNsKdrZIgxfRfW2vrdpPFhfMuHfWJHfwDPWFrTT-KnXD7GBJBTxYvSxiRDh3
相关文章推荐
- c++中的容器总结--
- 《C++ Primer Plus(第六版)》(35)(第十六章 string类和标准模板库 复习题答案)
- 计算逆序对数
- C语言 memset函数简单实现
- c++ const
- C++中的const
- c++primer(5th)15章 文本查询程序 代码解读(学习继承与多态)与修改+动物运动会代码(学习继承与多态,拷贝用构造函数,=重载运算符)
- C语言写的一个简易计算器
- WAVE录音
- WAVE播放
- pcl 1.8 + VS 2010 在win7 x64下的配置
- C++ std::map
- oc和c++混编
- C++中指针和引用的区别
- C++ bind函数适配器
- Postman使用及安装
- FFTW+VS2015 64&32位
- g++ -std=c++11
- C++ std::list
- C++第三课-之二(类和对象)