码迷,mamicode.com
首页 > 其他好文 > 详细

Intro to Makefile

时间:2017-01-03 09:59:37      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:.text   tps   file   complier   detail   get   lag   amp   hid   

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

#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

Intro to Makefile

标签:.text   tps   file   complier   detail   get   lag   amp   hid   

原文地址:http://blog.csdn.net/canhui_wang/article/details/53979851

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!