Makefile没有运行arm-none-eabi-ar没有链接所有.o文件

时间:2013-02-25 08:37:33

标签: makefile

我有以下Makefile

CC=arm-none-eabi-gcc
AR=arm-none-eabi-ar

vpath %.c src src/peripherals
vpath %.o out

CFLAGS = -g -O2 -Wall -DUSE_STDPERIPH_DRIVER
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -ffreestanding -nostdlib
CFLAGS += -Iinc -Iinc/cmsis -Iinc/peripherals -Iinc/stm32f4xx

OUT_DIR=out

SRCS = misc.c stm32f4xx_adc.c stm32f4xx_can.c stm32f4xx_crc.c stm32f4xx_cryp.c stm32f4xx_cryp_aes.c \
    stm32f4xx_cryp_des.c stm32f4xx_cryp_tdes.c stm32f4xx_dac.c stm32f4xx_dbgmcu.c stm32f4xx_dcmi.c stm32f4xx_dma.c \
    stm32f4xx_exti.c stm32f4xx_flash.c stm32f4xx_fsmc.c stm32f4xx_gpio.c stm32f4xx_hash.c stm32f4xx_hash_md5.c \
    stm32f4xx_hash_sha1.c stm32f4xx_i2c.c stm32f4xx_iwdg.c stm32f4xx_pwr.c stm32f4xx_rcc.c stm32f4xx_rng.c \
    stm32f4xx_rtc.c stm32f4xx_sdio.c stm32f4xx_spi.c stm32f4xx_syscfg.c stm32f4xx_tim.c stm32f4xx_usart.c \
    stm32f4xx_wwdg.c

OBJS = $(SRCS:.c=.o)

.PHONY: libstm32f4.a

all: libstm32f4.a

%.o : %.c
    mkdir -p $(OUT_DIR)
    $(CC) $(CFLAGS) -c -o $(OUT_DIR)/$@ $^

libstm32f4.a: $(OBJS)
    $(AR) -r $(OUT_DIR)/$@ $(OUT_DIR)/$(OBJS)

clean:
    rm -rf $(OUT_DIR)

但是当运行make时,我的.o文件正在构建好,但是arm-none-eabi-ar被调用的地方,我正在搞乱。

该行

$(AR) -r $(OUT_DIR)/$@ $(OUT_DIR)/$(OBJS)

可能是我出错的地方,它的输出是:

arm-none-eabi-ar -r out/libstm32f4.a out/misc.o stm32f4xx_adc.o stm32f4xx_can.o stm32f4xx_crc.o stm32f4xx_cryp.o stm32f4xx_cryp_aes.o stm32f4xx_cryp_des.o stm32f4xx_cryp_tdes.o stm32f4xx_dac.o stm32f4xx_dbgmcu.o stm32f4xx_dcmi.o stm32f4xx_dma.o stm32f4xx_exti.o stm32f4xx_flash.o stm32f4xx_fsmc.o stm32f4xx_gpio.o stm32f4xx_hash.o stm32f4xx_hash_md5.o stm32f4xx_hash_sha1.o stm32f4xx_i2c.o stm32f4xx_iwdg.o stm32f4xx_pwr.o stm32f4xx_rcc.o stm32f4xx_rng.o stm32f4xx_rtc.o stm32f4xx_sdio.o stm32f4xx_spi.o stm32f4xx_syscfg.o stm32f4xx_tim.o stm32f4xx_usart.o stm32f4xx_wwdg.o
arm-none-eabi-ar: creating out/libstm32f4.a
arm-none-eabi-ar: stm32f4xx_adc.o: No such file or directory
make: *** [libstm32f4.a] Error 1

当看到这个时,out / libstm32f4.a是正确的,但是包含所有* .o文件的第二个子句是完全错误的,只有out / misc.o以out /文件夹为前缀,而不是其余的,导致错误?

如何修复我的Makefile以使其在./out/中查找.o文件?我使用

vpath %.o out

错误,或者Makefile中的arm-none-eabi-ar指令不正确?

1 个答案:

答案 0 :(得分:1)

只需更改

$(AR) -r $(OUT_DIR)/$@ $(OUT_DIR)/$(OBJS)

$(AR) -r $(OUT_DIR)/$@ $(OUT_DIR)/*.o

DUH !!!