If for example, we have a directory structure like this.
/home/cpp/HelloWorld.cpp /HelloWorld.hpp /Main.cpp
* Makefile *
CC=g++ CFLAGS=-Wall OBJ=Main.o HelloWorld.o Main: $(OBJ) clean: rm -rf Main *.o
1. To build
make2. To clean
make cleanHere we use Makefile's implicit rules by only specifying the CC and CFLAGS implicit variables. For more information, see this link.
If now, we have a directory structure like this.
/home/cpp/lib/libhello.a /include/HelloWorld.hpp /Main.cpp* Makefile *
CC=g++ INCLUDEDIR=include LIBDIR=lib/libhello.a CFLAGS=-Wall -I$(INCLUDEDIR) OBJ=Main.o DEPS=$(INCLUDEDIR)/HelloWorld.hpp Main: $(OBJ) $(CC) -o Main $(OBJ) $(LIBDIR) $(CFLAGS) %.o: %.cpp $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) clean: rm -rf Main *.oFor more information about the automatic variables, such as $@, $<, see this link.
No comments:
Post a Comment