Abstract
This blog would show you what 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_hvoid tool1(char *);void tool1(constchar *);#endif
File1.cpp
#include <stdio.h>#include "file1.h"void tool1(char *str){ printf("This is file1 print: %s\n",str);}voidchar *str){ printf("This is file1 print: %s\n",str);}
File2.h
#ifndef file2_h#define file2_hvoid tool2(char *);void tool2(constchar *);#endif
File2.cpp
#include <stdio.h>#include "file2.h"void tool2(char *str){ printf("This is file2 print: %s\n",str);}voidchar *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"hello"; tool1(str1); constchar"hello"; tool1(str1_c); char"hello"; tool2(str2); constchar"hello"; tool2(str2_c);}
Makefile
CC: = g++cflags: =-gtarget: = Targetsrcs: = $ ( wildcard *. CPP) OBJS: = $ ( patsubst %cpp , %o , $ ( srcs)) All:$ ( TARGET) Clean%. O:%. CPP $ ( CC) $ ( CFLAGS)-C $< $ ( TARGET): $ ( OBJS) $ ( CC) $ ( CFLAGS)-O [email protected] $^ 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
Intro to Makefile