2012-12-20 24 views
8

Questo è fonte di confusione. Io ho la mia Makefile:GNU Produce un risultato completamente diverso

OBJECTS = 
INCLUDE_BUILD_PATH = /Users/wen/Projects/include 

# Change compilation settings here 
COMPILE = g++ 
override COMPILE_FLAGS += -O2 

# Change linker/compiler specific settings here 
LD_FLAGS := 
CC_FLAGS := -c -I$(INCLUDE_BUILD_PATH)/bigint 

# Add source extensions here 
SRC_EXT = cpp cc 

# Add header dependencies here 
HEADERS = $(wildcard *.hpp) $(wildcard $(INCLUDE_BUILD_PATH)/*/*.hh) 

# Add source files here 
CC_FILES = $(wildcard *.cpp) $(wildcard $(INCLUDE_BUILD_PATH)/*/*.cc) 
CC_O_BUFFER = $(CC_FILES) 
CC_O_BUFFER := $(CC_O_BUFFER:.cpp=.o) 
CC_O_BUFFER := $(CC_O_BUFFER:.cc=.o) 
OBJECTS = $(CC_O_BUFFER) 

# Change .exe name here 
EXE_NAME = maketest 

# Link object files 

$(EXE_NAME): $(OBJECTS) 
    $(COMPILE) $(COMPILE_FLAGS) $(LD_FLAGS) -o [email protected] $^ 

# Build source files 

define compile_rule 
%.o : %.$1 
     $$(COMPILE) $$(COMPILE_FLAGS) $$(CC_FLAGS) -o [email protected] $$< 
endef 
    $(foreach EXT,$(SRC_EXT),$(eval $(call compile_rule,$(EXT)))) 

# Clean 

clean: 
    rm -f $(OBJECTS) $(EXE_NAME) 

# Debug Build 

debug: 
    @echo "Rerun with COMPILE_FLAGS=-D_DEBUG" 

# Print variables 

print: 
    @echo $(CC_FILES) 
    @echo $(OBJECTS) 
    @echo $(HEADERS) 

è compilato con successo in un primo momento, ma poi si è fermato per nessun motivo e questo era l'output:

Yoshi-Air:maketest wen$ make 
c++ -c -o maketest.o maketest.cpp 
maketest.cpp:4:10: fatal error: 'BigIntegerLibrary.hh' file not found 
#include "BigIntegerLibrary.hh" 
     ^
1 error generated. 

fosse il problema, non ho nemmeno dirlo a usa "C++" nel Makefile ma "g ++" invece. Inoltre, quando ho cancellato CC_FLAGS il -c era ancora lì. È come se Make avesse una mente propria.

Se uso make print stampare le mie variabili sembra essere tutto a posto:

maketest.cpp /Users/wen/Projects/include/bigint/BigInteger.cc /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.cc /Users/wen/Projects/include/bigint/BigIntegerUtils.cc /Users/wen/Projects/include/bigint/BigUnsigned.cc /Users/wen/Projects/include/bigint/BigUnsignedInABase.cc 
maketest.o /Users/wen/Projects/include/bigint/BigInteger.o /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.o /Users/wen/Projects/include/bigint/BigIntegerUtils.o /Users/wen/Projects/include/bigint/BigUnsigned.o /Users/wen/Projects/include/bigint/BigUnsignedInABase.o 
maketest.hpp /Users/wen/Projects/include/bigint/BigInteger.hh /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.hh /Users/wen/Projects/include/bigint/BigIntegerLibrary.hh /Users/wen/Projects/include/bigint/BigIntegerUtils.hh /Users/wen/Projects/include/bigint/BigUnsigned.hh /Users/wen/Projects/include/bigint/BigUnsignedInABase.hh /Users/wen/Projects/include/bigint/NumberlikeArray.hh 

Qualsiasi aiuto o consiglio sarà apprezzato. Grazie!

Aggiornamento

ho aggiornato il mio print per stampare l'esecuzione atteso di compilazione:

print: 
    @echo $(CC_FILES) 
    @echo $(OBJECTS) 
    @echo $(HEADERS) 
    @echo "Compiles with:" 
    @echo $(COMPILE) $(COMPILE_FLAGS) $(LD_FLAGS) $(CC_FLAGS) 

Risultato:

maketest.cpp /Users/wen/Projects/include/bigint/BigInteger.cc /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.cc /Users/wen/Projects/include/bigint/BigIntegerUtils.cc /Users/wen/Projects/include/bigint/BigUnsigned.cc /Users/wen/Projects/include/bigint/BigUnsignedInABase.cc 
maketest.o /Users/wen/Projects/include/bigint/BigInteger.o /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.o /Users/wen/Projects/include/bigint/BigIntegerUtils.o /Users/wen/Projects/include/bigint/BigUnsigned.o /Users/wen/Projects/include/bigint/BigUnsignedInABase.o 
maketest.hpp /Users/wen/Projects/include/bigint/BigInteger.hh /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.hh /Users/wen/Projects/include/bigint/BigIntegerLibrary.hh /Users/wen/Projects/include/bigint/BigIntegerUtils.hh /Users/wen/Projects/include/bigint/BigUnsigned.hh /Users/wen/Projects/include/bigint/BigUnsignedInABase.hh /Users/wen/Projects/include/bigint/NumberlikeArray.hh 
Yoshi-Air:maketest wen$ make print 
maketest.cpp /Users/wen/Projects/include/bigint/BigInteger.cc /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.cc /Users/wen/Projects/include/bigint/BigIntegerUtils.cc /Users/wen/Projects/include/bigint/BigUnsigned.cc /Users/wen/Projects/include/bigint/BigUnsignedInABase.cc 
maketest.o /Users/wen/Projects/include/bigint/BigInteger.o /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.o /Users/wen/Projects/include/bigint/BigIntegerUtils.o /Users/wen/Projects/include/bigint/BigUnsigned.o /Users/wen/Projects/include/bigint/BigUnsignedInABase.o 
maketest.hpp /Users/wen/Projects/include/bigint/BigInteger.hh /Users/wen/Projects/include/bigint/BigIntegerAlgorithms.hh /Users/wen/Projects/include/bigint/BigIntegerLibrary.hh /Users/wen/Projects/include/bigint/BigIntegerUtils.hh /Users/wen/Projects/include/bigint/BigUnsigned.hh /Users/wen/Projects/include/bigint/BigUnsignedInABase.hh /Users/wen/Projects/include/bigint/NumberlikeArray.hh 
Compiles with: 
g++ -O2 -c -I/Users/wen/Projects/include/bigint 

Ciò dimostra che marca sa quello che volevo, ma quando si costruisce è completamente diverso: c++ anziché g++?!

Aggiornamento 2:

c++ invoca clang, installato sul mio sistema.

Soluzione da Alex B:

Ma dalla riga di comando di compilazione sembra Marchio sta cercando di usare la regola suffissi implicita, e ignora la regola modello.

Ho provato .SUFFIXES: e sì, ha rilevato una regola non trovata. Grazie, andrò a consultare il manuale.

+0

Il mio consiglio? Controlla se esiste "" BigIntegerLibrary.hh "". –

+0

Questo mi è stato detto molte volte; esiste. Il problema è che make non ha incluso CC_FLAGS correttamente per passare il percorso di inclusione al compilatore. –

+0

Oh. E così, vediamo ... –

risposta

2

Come ho detto nel commento, funziona nel mio ambiente (Mac OSX, GNU Make 3.81), quindi il problema potrebbe essere che il makefile che hai pubblicato è incompleto o stai utilizzando una versione diversa di Make.

Ma dalla riga di comando della compilazione sembra che Make stia cercando di utilizzare la regola del suffisso implicito e ignora la regola del modello.

È possibile indicare a Make di ignorare le regole predefinite specificando un elenco vuoto di suffissi, in modo da poter eseguire il debug del problema ulteriormente.

.SUFFIXES: 
+0

"Ma dalla riga di comando della compilazione sembra che Make stia cercando di utilizzare la regola del suffisso implicito e ignora la regola del pattern." Questo lo spiega completamente. Lo esaminerò. –

+0

Potrei avere + 10 la tua risposta che potrei: D –

Problemi correlati