要使用库我必须更改makefile以使用交叉编译器 arm-none-eabi -g ++ 而不是 arm-none-eabi-gcc ;但是,由于一些奇怪的原因,我不断收到No rule to make target
错误。我删除了依赖项,只留下了启动代码和main,我也尝试使用文件的绝对路径。但是,我继续收到错误。有没有人有任何建议?
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.
答案 0 :(得分:2)
这条规则:
$(BUILDDIR)/%.o: %.c
介绍了如何从$(BUILDDIR)/foo.o
创建文件foo.c
。但是您现在想要编译.cpp
文件。只需将配方中的编译器变量从$(CC)
更改为$(CXX)
,不会更改目标或先决条件的描述!您需要添加一个 new 规则,告诉您如何编译.cpp
文件:
$(BUILDDIR)/%.o: %.cpp
mkdir -p $(dir $@)
$(CXX) -c $(CXXFLAGS) $< -o $@
另外,您可能应该在$(CC)
配方中放回%.c
编译调用;使用C ++编译器编译C代码通常不是一个好主意。