Makefile:目标“ foo.o”的配方失败

时间:2018-11-21 04:21:17

标签: c++ makefile dependencies

我有一个要编译的C ++软件包。它包含以下内容

Coordinate.h 
Coordinate.cpp
Hitbox.h
Hitbox.cpp
Octree.h
Octree.cpp
main.cpp

Main包含所有头文件。 Octree依赖于Hitbox.h和Coordinate.h,而Hitbox继承自Coordinate.h

我的制作文件如下:

ARTIFACT = main

#Build architecture/variant string, possible values: x86, armv7le, etc...
PLATFORM ?= x86_64

#Build profile, possible values: release, debug, profile, coverage
BUILD_PROFILE ?= debug

CONFIG_NAME ?= $(PLATFORM)-$(BUILD_PROFILE)
OUTPUT_DIR = build/$(CONFIG_NAME)
TARGET = $(OUTPUT_DIR)/$(ARTIFACT)

#Compiler definitions

CC = qcc -Vgcc_nto$(PLATFORM)
CXX = qcc -lang-c++ -Vgcc_nto$(PLATFORM)
LD = $(CXX)

#User defined include/preprocessor flags and libraries

INCLUDES += -$(OUTPUT_DIR)/src/Coordinate.h
INCLUDES += -$(OUTPUT_DIR)/src/Hitbox.h
INCLUDES += -$(OUTPUT_DIR)/src/Octree.h

LIBS += -$(OUTPUT_DIR)/src/Coordinate.cpp
LIBS += -$(OUTPUT_DIR)/src/Hitbox.cpp
LIBS += -$(OUTPUT_DIR)/src/Octree.cpp
#LIBS += -L../mylib/$(OUTPUT_DIR) -lmylib

#Compiler flags for build profiles
CCFLAGS_release += -O2
CCFLAGS_debug += -g -O0 -fno-builtin
CCFLAGS_coverage += -g -O0 -ftest-coverage -fprofile-arcs -nopipe -Wc,-auxbase-strip,$@
LDFLAGS_coverage += -ftest-coverage -fprofile-arcs
CCFLAGS_profile += -g -O0 -finstrument-functions
LIBS_profile += -lprofilingS

#Generic compiler flags (which include build type flags)
CCFLAGS_all += -Wall -fmessage-length=0
CCFLAGS_all += $(CCFLAGS_$(BUILD_PROFILE))
#Shared library has to be compiled with -fPIC
#CCFLAGS_all += -fPIC
LDFLAGS_all += $(LDFLAGS_$(BUILD_PROFILE))
LIBS_all += $(LIBS_$(BUILD_PROFILE))
DEPS = -Wp,-MMD,$(@:%.o=%.d),-MT,$@

#Macro to expand files recursively: parameters $1 -  directory, $2 - extension, i.e. cpp
rwildcard = $(wildcard $(addprefix $1/*.,$2)) $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2))

#Source list
SRCS = $(call rwildcard, src, c cpp)

#Object files list
OBJS = $(addprefix $(OUTPUT_DIR)/,$(addsuffix .o, $(basename $(SRCS))))

#Compiling rule
$(OUTPUT_DIR)/%.o: %.c
    @mkdir -p $(dir $@)
    $(CC) -c $(DEPS) -o $@ $(INCLUDES) $(CCFLAGS_all) $(CCFLAGS) $<
$(OUTPUT_DIR)/%.o: %.cpp
    @mkdir -p $(dir $@)
    $(CXX) -c $(DEPS) -o $@ $(INCLUDES) $(CCFLAGS_all) $(CCFLAGS) $<

#Linking rule
$(TARGET):$(OBJS)
    $(LD) -o $(TARGET) $(LDFLAGS_all) $(LDFLAGS) $(OBJS) $(LIBS_all) $(LIBS)

#Rules section for default compilation and linking
all: $(TARGET)

clean:
    rm -fr $(OUTPUT_DIR)

rebuild: clean all

#Inclusion of dependencies (object files to source and includes)
-include $(OBJS:%.o=%.d)

但是第60-63行似乎不起作用:

$(OUTPUT_DIR)/%.o: %.cpp
@mkdir -p $(dir $@)
$(CXX) -c $(DEPS) -o $@ $(INCLUDES) $(CCFLAGS_all) $(CCFLAGS) $<

此行对应于以下内容:

qcc -lang-c++ -Vgcc_ntox86_64 -c -Wp,-MMD,build/x86_64-debug/src/main.d,-MT,build/x86_64-debug/src/main.o -o build/x86_64-debug/src/main.o -build/x86_64-debug/src/Coordinate.h -build/x86_64-debug/src/Hitbox.h -build/x86_64-debug/src/Octree.h -Wall -fmessage-length=0 -g -O0 -fno-builtin  src/main.cpp

错误消息是:

cc: unknown option: -build/x86_64-debug/src/Coordinate.h
Makefile:61: recipe for target 'build/x86_64-debug/src/Octree.o' failed
make: *** [build/x86_64-debug/src/Octree.o] Error 1
make: *** Waiting for unfinished jobs....
cc: unknown option: -build/x86_64-debug/src/Coordinate.h
Makefile:61: recipe for target 'build/x86_64-debug/src/main.o' failed
make: *** [build/x86_64-debug/src/main.o] Error 1

知道我在做什么错吗?

通过使用常用的linux gcc命令语法链接依赖项,代码可以正常编译

0 个答案:

没有答案