linux之makefile
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键隔 开
详情参考