如何在STM32CubeMX Makefile中添加静态库?视窗

问题描述

我有一个STM32CubeMX为项目生成的Makefile。我在以下文件夹中有一个预编译的静态库文件lib1.a。

Project Dir/
 Core/
  Lib/
   lib1.a header1.h header2.h

我一直在尝试添加此静态库文件,但是它说

找不到-llib1

如何将此库添加到我的Makefile中?我正在Windows 10上使用VS Code来通过GNU ARM和OpenOCD编译Makefile。

######################################
# target
######################################
TARGET = APComV2


######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -Og


#######################################
# paths
#######################################
# Build path
BUILD_DIR = build

######################################
# source

######################################
# C sources
C_SOURCES =  \
Core/Src/main.c \
Core/Src/gpio.c \
Core/Src/usart.c \
Core/Src/stm32l4xx_it.c \
Core/Src/stm32l4xx_hal_msp.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c \
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c \
Core/Src/system_stm32l4xx.c

# ASM sources
ASM_SOURCES =  \
startup_stm32l433xx.s


#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via 
GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S

#######################################
# CFLAGS
#######################################
# cpu
cpu = -mcpu=cortex-m4

# fpu
FPU = -mfpu=fpv4-sp-d16

# float-abi
FLOAT-ABI = -mfloat-abi=hard

# mcu
MCU = $(cpu) -mthumb $(FPU) $(FLOAT-ABI)

# macros for gcc
# AS defines
AS_DEFS = 

# C defines
C_DEFS =  \
-DUSE_HAL_DRIVER \
-DSTM32L433xx


# AS includes
AS_INCLUDES = 

# C includes
C_INCLUDES =  \
-ICore/Inc \
-ICore/Lib/ \
-IDrivers/STM32L4xx_HAL_Driver/Inc \
-IDrivers/STM32L4xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32L4xx/Include \
-IDrivers/CMSIS/Include


# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections - 
ffunction-sections

CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections - 
ffunction-sections

ifeq ($(DEBUG),1)
CFLAGS += -g -gdwarf-2
endif


# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"


#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32L433RCTxP_FLASH.ld

# libraries
LIBS = -lc -lm -lnosys -llib1
LIBDIR = -LCore/Lib/
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,- 
Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections

# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex 
$(BUILD_DIR)/$(TARGET).bin


#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o 
$@

$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@

$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@

$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@    

$(BUILD_DIR):
mkdir $@        

#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)

#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)

# *** EOF ***

编辑:我已经在上面添加了完整的Makefile。我在此文件添加的行是:

-ICore / Lib \

-llib1 -LCore / Lib /

我正在使用以下命令。

使-j4全部

所有源代码都可以很好地编译,但是在链接库时,它会提供以下输出

arm-none-eabi-gcc build/main.o build/gpio.o build/usart.o 
build/stm32l4xx_it.o build/stm32l4xx_hal_msp.o build/stm32l4xx_hal_tim.o 
build/stm32l4xx_hal_tim_ex.o build/stm32l4xx_hal_uart.o 
build/stm32l4xx_hal_uart_ex.o build/stm32l4xx_hal.o build/stm32l4xx_hal_i2c.o 
build/stm32l4xx_hal_i2c_ex.o build/stm32l4xx_hal_rcc.o 
build/stm32l4xx_hal_rcc_ex.o build/stm32l4xx_hal_flash.o 
build/stm32l4xx_hal_flash_ex.o build/stm32l4xx_hal_flash_ramfunc.o 
build/stm32l4xx_hal_gpio.o build/stm32l4xx_hal_dma.o 
build/stm32l4xx_hal_dma_ex.o build/stm32l4xx_hal_pwr.o 
build/stm32l4xx_hal_pwr_ex.o build/stm32l4xx_hal_cortex.o 
build/stm32l4xx_hal_exti.o build/system_stm32l4xx.o 
build/startup_stm32l433xx.o -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 - 
mfloat-abi=hard -specs=nano.specs -TSTM32L433RCTxP_FLASH.ld -LCore/Lib/ -lc - 
lm -lnosys -llib1 -Wl,-Map=build/APComV2.map,--gc-sections -o 
build/APComV2.elf

c:/program files (x86)/gnu arm embedded toolchain/9 2020-q2- 
update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none- 
eabi/bin/ld.exe: cannot find -llib1

collect2.exe: error: ld returned 1 exit status

make: *** [build/APComV2.elf] Error 1

The terminal process 
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command make -j4 
all" terminated with exit code: 1.

请指出我的错误并帮助我解决链接器问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)