The problem with makefile is creating .gch files instead of files.

So, I am making a program to test the effectiveness of certain data structures. I have all the .h files, and I made a very scary make file, which is probably erroneous, although it seems to work to a certain extent. Instead of creating .o files, it makes .gch files, so when it tries to get all the .o files, they are not found. This is my makefile

prog1: main.o dsexceptions.o BinarySearchTree.o SplayTree.o RedBlackTree.o AvlTree.o
                g++ -Wall -g -o prog1 main.o dsexceptions.h.gch BinarySearchTree.h.gch SplayTree.h.gch RedBlackTree.h.gch AvlTree.h.gch

main.o: main.cpp AvlTree.h RedBlackTree.h SplayTree.h BinarySearchTree.h dsexceptions.h
                g++ -Wall -g -c main.cpp

#shape.o: shape.cpp shape.h grid.h
#               g++ -Wall -g -c shape.cpp

dsexceptions.o: dsexceptions.h
                g++ -Wall -g -c dsexceptions.h

BinarySearchTree.o: BinarySearchTree.h dsexceptions.h
                    g++ -Wall -g -c BinarySearchTree.h

SplayTree.o: SplayTree.h dsexceptions.h
             g++ -Wall -g -c SplayTree.h

RedBlackTree.o: RedBlackTree.h dsexceptions.h
                g++ -Wall -g -c RedBlackTree.h

AvlTree.o: AvlTree.h dsexceptions.h
           g++ -Wall -g -c AvlTree.h

clean:
                rm -f main main.exe  main.o dsexceptions.o BinarySearchTree.o SplayTree.o RedBlackTree.o AvlTree.o *.gch
+3
source share
3 answers

.h . .cpp, .h . ( .gch .) .o. # .cpp .

prog1: main.o
        g++ -Wall -g -o prog1 main.o

main.o: main.cpp AvlTree.h RedBlackTree.h SplayTree.h BinarySearchTree.h dsexceptions.h
        g++ -Wall -g -c main.cpp

clean:
        rm -f prog1 main.o
+17

bstpierre, make :

CC = g++ -Wall -g -o $@

MODULE = AvlTree BinarySearchTree RedBlackTree SplayTree
OBJECTS = $(addsuffix .o,$(MODULES))

prog1: main.o dsexceptions.o $(OBJECTS)
       $(CC) $^ 

main.o: $(addsuffix .h,$(MODULES))

$(OBJECTS) main.o : %.cpp %.h dsexceptions.h
    $(CC) -c $&lt

clean:
 rm -f main main.exe *.o *.gch
+1

, SConstruct, SCons :)

Program('main.cpp') # Yeah, it that simple :)

SCons .

+1
source

Source: https://habr.com/ru/post/1718521/


All Articles