Intro to Makefile

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.