ITeye博客

linux之makefile

labreeze · 2012-09-20 20:41 · 操作系统与软件安装 · 操作系统 · Markdown

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://quanwei.blog.51cto.com/1410588/308092

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。