声明:因网易博客将关闭,移到此
/include/test.h
/src/test.cpp
main.cpp
Makefile
-----------------------------------------------------------------
test.h
#ifndef __TEST_H__
#define __TEST_H__
#include<iostream>
#include<string.h>
using namespace std;
class test
{
public:
test();
virtual ~test();
void echo();
};
#endif //__TEST_H__
-----------------------------------------------------------------
test.cpp
#include "test.h"
test::test(){}
test::~test(){}
test::echo(){cout<<"test::echo()"<<endl;}
-----------------------------------------------------------------
main.cpp
#include "test.h"
int main()
{
test a;
a.echo();
return 0;
}
-----------------------------------------------------------------
Makefile
CXX=g++
FLAGS=-Wall -o2 -g
EXE=main
objects=test.o main.o
vapth %.cpp src
vapth %.h include
all:$(EXE)
$(EXE):$(objects)
$(CXX) $(FLAGS) -o $@ $(objects)
$(objects):%.o:%.cpp
$(CXX) $(FLAGS) -c $< -o $@
clean:
rm $(objects) $(EXE)
-----------------------------------------------------------------
# make main.cpp
CXX=g++
FLAGS=-Wall -O2 -g
EXE=main
EXEOBJ=main.o
objects=test.o
vpath %.cpp src
vpath %.h include
all:$(EXE)
$(EXE):$(objects) $(EXEOBJ)
$(CXX) $(FLAGS) -o $@ $(objects) $(EXEOBJ)
$(EXEOBJ):$(EXE).cpp test.h
$(CXX) $(FLAGS) -c $< -o $@ -I include
$(objects):%.o:%.cpp %.h
$(CXX) $(FLAGS) -c $< -o $@ -I include
clean:
rm $(objects) $(EXE)