c++;makefile应该是什么样子 假设我有以下C++文件,我应该如何为他们编写一个基本的Mag文件(使用G++)? a、 cpp a.h,b.cpp b.h,c.cpp c.h,main.h 当b.h包括a.h时,c.h包括b.h,main.h包括c.h
非常感谢,这样你就可以写了c++;makefile应该是什么样子 假设我有以下C++文件,我应该如何为他们编写一个基本的Mag文件(使用G++)? a、 cpp a.h,b.cpp b.h,c.cpp c.h,main.h 当b.h包括a.h时,c.h包括b.h,main.h包括c.h,makefile,Makefile,非常感谢,这样你就可以写了 EXE := exe CC := g++ CPP_FILES := a.cpp b.cpp c.cpp HPP_FILES := a.h b.h c.h main.h $(EXE) : $(CPP_FILES) $(HPP_FILES) $(CC) -o $@ $(CPP_FILES) .PHONY : clean clean: rm -rf $(EXE) *.o 如何编译文件?假设您现在有test.cpp和test.h来编译和链接它: g
EXE := exe
CC := g++
CPP_FILES := a.cpp b.cpp c.cpp
HPP_FILES := a.h b.h c.h main.h
$(EXE) : $(CPP_FILES) $(HPP_FILES)
$(CC) -o $@ $(CPP_FILES)
.PHONY : clean
clean:
rm -rf $(EXE) *.o
如何编译文件?假设您现在有
test.cpp
和test.h
来编译和链接它:
g++ -c test.c
g++ -o test test.o
最简单的Makefile
:
test: test.o #means test depends on test.o
g++ -o test test.o
test.o: test.cpp test.h #means test.o depends on test.cpp and test.h
g++ -c test.cpp
#if you want clean? add below line too.
clean:
rm test test.o
如果你的应用程序依赖于多个文件,那么
test: test1.o test2.o test3.o #means your app depends on test1.o test2.o and test3.o
g++ -o test test1.o test2.o test3.o
test1.o: test1.cpp test1.h
g++ -c test1.cpp
test2.o: test2.cpp test2.h
g++ -c test2.cpp
...
如果我还有包含test.h的test2.h,test2.cpp,我应该如何编写它?