生成文件的问题

Issues with makefile

要使用库,我必须更改 makefile 以使用交叉编译器 arm-none-eabi-g++ 而不是 arm-none-eabi-gcc;但是,由于某些奇怪的原因,我不断收到 No rule to make target 错误。我删除了依赖项,只留下启动代码和主要代码,我还尝试使用文件的绝对路径。但是,我继续收到错误。有人有什么建议吗?

PROJECT_NAME=test-liv

BUILDDIR = build

LIBDIR = ../common
DEVICE = $(LIBDIR)/STM32F4xx
CORE = $(LIBDIR)/CMSIS
PERIPH = $(LIBDIR)/STM32F4xx_StdPeriph_Driver
PROJHEADERS = inc
PROJ_LIBDIR = lib

#SOURCES = src/main.cpp
SOURCES = startup_stm32f4xx.S
SOURCES += system_stm32f4xx.c
SOURCES += LibraryHacks.cpp

SOURCES += src/main.cpp
#SOURCES += $(PERIPH)/src/
#PROJECT SOURCES
#SOURCES += $(PROJ_LIBDIR)/src/


OBJECTS = $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(abspath $(basename $(SOURCES)))))

INCLUDES += -I$(DEVICE) \
            -I$(PROJHEADERS) \
            -I$(CORE) \
            -I$(PERIPH)/inc \
            -I$(PROJ_LIBDIR)/inc \
            -Isrc \
            -I.

ELF = $(BUILDDIR)/$(PROJECT_NAME).elf
HEX = $(BUILDDIR)/$(PROJECT_NAME).hex
BIN = $(BUILDDIR)/$(PROJECT_NAME).bin

CXX = arm-none-eabi-g++
LD = arm-none-eabi-g++
AR = arm-none-eabi-ar
OBJCOPY = arm-none-eabi-objcopy
GDB = arm-none-eabi-gdb
SIZE = arm-none-eabi-size

CXXFLAGS  = -O0 -g -Wall -I.\
   -std=c++11 -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork \
   -mfpu=fpv4-sp-d16 -mfloat-abi=hard \
   $(INCLUDES) -DUSE_STDPERIPH_DRIVER

SEMIHOSTING_FLAGS = --specs=rdimon.specs -lc -lrdimon

LDSCRIPT = stm32_flash.ld
LDFLAGS += -T$(LDSCRIPT) -mthumb -mcpu=cortex-m4 

$(BIN): $(ELF)
    $(OBJCOPY) -O binary $< $@

$(HEX): $(ELF)
    $(OBJCOPY) -O ihex $< $@

$(ELF): $(OBJECTS)
    $(LD) $(LDFLAGS) $(CFLAGS) $(SEMIHOSTING_FLAGS) -o $@ $(OBJECTS) $(LDLIBS)
    $(SIZE) $@

$(BUILDDIR)/%.o: %.c
    mkdir -p $(dir $@)
    $(CXX) -c $(CXXFLAGS) $< -o $@

$(BUILDDIR)/%.o: %.S
    mkdir -p $(dir $@)
    $(CXX) -c $(CXXFLAGS) $< -o $@

flash: $(BIN)
    st-flash write $(BIN) 0x8000000

debug: $(ELF)
    $(GDB) -tui $(ELF)

openocd: $(ELF)
    openocd -f board/stm32f4discovery.cfg

all: $(HEX) $(BIN) $(ELF)

functions: all

.PHONY: clean
clean:
    rm -rf build

编辑:完整的错误消息我删除了其他依赖项并留下了 LibraryHacks 和 main 并且取决于哪个是第一个它仍然给我同样的错误

mkdir -p build//*Removed*/
arm-none-eabi-g++ -c -O0 -g -Wall -I. -std=c++11 -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfpu=fpv4-sp-d16 -mfloat-abi=hard -I../common/STM32F4xx -Iinc -I../common/CMSIS -I../common/STM32F4xx_StdPeriph_Driver/inc -Ilib/inc -Isrc -I. -DUSE_STDPERIPH_DRIVER /*Removed*/startup_stm32f4xx.S -o build//*Removed*/startup_stm32f4xx.o
mkdir -p build//*Removed*/
arm-none-eabi-g++ -c -O0 -g -Wall -I. -std=c++11 -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfpu=fpv4-sp-d16 -mfloat-abi=hard -I../common/STM32F4xx -Iinc -I../common/CMSIS -I../common/STM32F4xx_StdPeriph_Driver/inc -Ilib/inc -Isrc -I. -DUSE_STDPERIPH_DRIVER /*Removed*/system_stm32f4xx.c -o build//*Removed*/system_stm32f4xx.o
make: *** No rule to make target `build//*Removed*/LibraryHacks.o', needed by `build/hx8352a-lcd.elf'.  Stop.

这条规则:

$(BUILDDIR)/%.o: %.c

描述如何从 foo.c 创建文件 $(BUILDDIR)/foo.o。但是你现在想编译一个 .cpp 文件。只是将配方中的编译器变量从 $(CC) 更改为 $(CXX) 不会更改目标或先决条件的描述!您需要添加一个 new 规则告诉 make 如何编译您的 .cpp 文件:

$(BUILDDIR)/%.o: %.cpp
        mkdir -p $(dir $@)
        $(CXX) -c $(CXXFLAGS) $< -o $@

此外,您可能应该在 %.c 配方中放回 $(CC) 编译调用;用 C++ 编译器编译 C 代码通常不是一个好主意。