2009-09-25 4 views
3

Donc, je fais un programme pour tester l'efficacité de certaines structures de données. J'ai tous les fichiers .h et j'ai fait un makefile très terrible qui est probablement faux, bien qu'il semble fonctionner jusqu'à un certain point. Au lieu de faire des fichiers .o, il fait des fichiers .gch, donc quand il essaie d'accéder à tous les fichiers .o ils ne sont pas trouvés. Ceci est mon makefileProblème avec le makefile de faire des fichiers .gch au lieu de fichiers 0.

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 

Répondre

17

Vous ne voulez pas nourrir vos fichiers .h au compilateur. Compilez uniquement le fichier .cpp, qui doit inclure vos fichiers .h. (Les fichiers .gch sont des en-têtes précompilés.) Vous n'avez pas besoin de fichiers .o pour vos en-têtes, il suffit de les inclure dans votre fichier .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 
+1

Wow, je suis un idiot MERCI BEAUCOUP! –

1

Vous avez déjà la solution de bstpierre, mais juste pour le plaisir est ici ma version de votre makefile:

 
CC = g++ -Wall -g -o [email protected] 

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 $< 

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

Et pour faire bonne mesure, voici mon SConstruct, parce SCons est tellement mieux:)

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

Vous pouvez regarder SCons here.

Questions connexes