---
title: "linux之makefile"
author: "labreeze"
date: "2012-09-20T20:41:46Z"
tags: []
categories: ["操作系统"]
slug: "linux-makefile"
draft: false
lastmod: "2020-05-23T01:27:09Z"
id: 1682576
url: "https://labreeze.iteye.com/blog/1682576"
---

1.hello.h的内容

 

```
#ifndef HELLO_H_
#define HELLO_H_
class hello{
        public:
                void print();
};

#endif
```

 2.hello.cpp的内容

 

 

```
#include<iostream>
using namespace std;

void hello::print(){
        cout<<"hello,welcome to project compile test"<<endl;
}
```

 

 3.main.cpp

 

```
#include<iostream>
using namespace std;
int main(){
        hello h;
        h.print();
        return 0;

}
```

 4.makefile

 

```
# written by young on June 27th, 2009
TARGET = .
CC = g++
CFLAGS = -g
CFLAGC = -c

MAINC = main.cpp
HELLO = hello.cpp
OBJ = hello.o

INCLUDE = -I$(TARGET)
EXEC = $(TARGET)/main

all: $(EXEC)
$(EXEC): $(OBJ) $(MAINC)
        $(CC) $(CFLAGS) $(OBJ) $(MAINC) $(INCLUDE) -o $@
        if [ -f *.o ]; then rm -f *.o; fi
        @echo "<<<<<< $@ is created successfully! >>>>>>"
        $(OBJ): $(HELLO)
        $(CC) $(CFLAGC) $(HELLO) -o $@
        clean:
        rm -f $(EXEC)
```

 调用makefile时候  有时候因为拷过来的字符问题会报\*\*\*遗漏分隔符 是因为中文字符的问题 或者shell命令加上tab键隔  开

 

详情参考

[http://blog.sina.com.cn/s/blog\_5357c0af0100j72z.html](http://blog.sina.com.cn/s/blog_5357c0af0100j72z.html)

[http://quanwei.blog.51cto.com/1410588/308092](http://quanwei.blog.51cto.com/1410588/308092)