Reputation: 4296
I have been working on this makefile for quite some time now and I can't find the solution to my problem. Here is the makefile:
# Compiler:
CPPFLAGS = $(OPT_FLAGS) $(DEBUG_FLAGS) $(STANDARD_FLAGS) \
$(WARN_AS_ERRORS_FLAGS)
# Source files, headers, etc.:
OBJ_DIR = $(CX_BUILD_ROOT)/tests/unit
OUT_DIR = $(CX_BUILD_ROOT)/tests/unit
INCLUDES = -I$(CX_SRC_ROOT)/cXbase/publicAPI
LIBINCLUDES = -L$(CX_BUILD_ROOT)/connectx/libs
VPATH = tests
SRCS = cxUnitTests.cpp\
test_Player.cpp\
test_Name.cpp\
test_Game.cpp\
test_GameBoard.cpp\
test_Disc.cpp\
test_Color.cpp\
test_AsciiColorCode.cpp\
OBJS = test_Player.o\
test_Name.o\
test_Game.o\
test_GameBoard.o\
test_Disc.o\
test_Color.o\
test_AsciiColorCode.o\
LIBS = -lgtest\
-lgtest_main\
-lpthread\
-lcXbase
# Product:
MAIN = cxUnitTests.out
all: make_dir $(MAIN)
$(MAIN): $(OBJS)
@echo Invoquing GCC...
$(CPPC) $(LIBINCLUDES) -o $(OUT_DIR)/$(MAIN) $(OBJS) $(LIBS)
@echo $(MAIN) has been compiled and linked!
$(OBJ_DIR)/%.o: %.cpp
@echo Invoquing GCC...
$(CPPC) $(CPPFLAGS) $(INCLUDES) -c $< -o $@
@echo Object files created!
make_dir:
mkdir -p $(OBJ_DIR)
mkdir -p $(OUT_DIR)
clean:
@echo Removing object files...
$(RM) $(OBJ_DIR)/*.o
@echo Object files removed!
mrproper: clean
@echo Cleaning project...
$(RM) $(OUT_DIR)/$(MAIN)
@echo Project cleaned!
depend: $(SRCS)
@echo Finding dependencies...
makedepend $(INCLUDES) $^
@echo Dependencies found!
All values in the "Source files, headers, etc" section are defined in other makefiles from which this makefile is invoked with the $(MAKE) -C
option They can all be @echo
ed and the resultant values are good. When I run make
, I get:
g++ -g3 -std=c++0x -pedantic-errors -Wall -Wextra -Werror -Wconversion -c -o test_Player.o tests/test_Player.cpp
and
tests/test_Player.cpp:36:30: fatal error: publicAPI/Player.h: No such file or directory
It seems that make
cannot access the content of the INCLUDES
variable for some reason. I use Gnu-make.
Can you see what is wrong?
Regards
Upvotes: 2
Views: 4970
Reputation: 4296
I finally found the problem. In fact, there were two:
INCLUDES
variable should have been set to
$(CX_SRC_ROOT)/cXbase
instead of $(CX_SRC_ROOT)/cXbase/publicAPI
since, like the error message shows, the include file for Player
is looked for in publicAPI/Player.h
so publicAPI
was there
twice, but didn't show twice in the @echo
.$(OBJ_DIR)/objectFile.o
.Upvotes: 0
Reputation: 20990
Make is using its built-in rule for compiling C++ files because your pattern rule $(OBJ_DIR)/%.o: %.cpp
doesn't match your list of objects. By coincidence you've used one of the variables that the built-in recipe uses (CPPFLAGS
), but make makes no use of INCLUDES
.
One way to fix it would be to put something like the following after your list of objects
OBJS := $(addprefix $(OBJ_DIR)/,$(OBJS))
Upvotes: 1