My makefile working when I remove $(OBJ_DIR) but I want my *.o files to extracted to be in lib folder.
Here is my makefile:
CC=g++
vpath %.h include
vpath %.cpp src
vpath %.o lib
OUT_DIR = bin
OBJDIR = lib
CFLAGS = -O2 -Wall -pedantic
LIBS = -lnsl -lm
OBJS = $(OBJDIR)/main.o $(OBJDIR)/AVLTree.o $(OBJDIR)/AVLTreeNode.o $(OBJDIR)/PersonData.o $(OBJDIR)/Stack.o
all:program
program:$(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(OUT_DIR)/program -static-libstdc++
$(OBJDIR)/%.o: %.cpp
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
.PHONY : clean
clean :
rm -f *.o $(OUT_DIR)/main.exe
and it gives this error:
> g++: error: lib/main.o: No such file or directory g++: error:
> lib/AVLTree.o: No such file or directory g++: error:
> lib/AVLTreeNode.o: No such file or directory g++: error:
> lib/PersonData.o: No such file or directory g++: error: lib/Stack.o:
> No such file or directory
.o files created in Projects folder but They must be in lib folder.
CC=g++
vpath %.h include
vpath %.cpp src
vpath %.o lib
OUT_DIR = bin
OBJDIR = lib
CFLAGS = -O2 -Wall -pedantic
LIBS = -lnsl -lm
OBJS = $(OBJDIR)/main.o $(OBJDIR)/AVLTree.o $(OBJDIR)/AVLTreeNode.o $(OBJDIR)/PersonData.o $(OBJDIR)/Stack.o
all:program
program:$(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(OUT_DIR)/program -static-libstdc++
$(OBJDIR)/%.o: %.cpp
$(CC) -c -o $@ $<
.PHONY : clean
clean :
rm -f *.o $(OUT_DIR)/main.exe
I dont know why but now it works perfectly!