Добрый день, подскажите, есть директория с проектом и библиотеками
структура директории
/---------------------
main.c
lib
|
|-------cmsis
|-------mylib
|
|--------led
|
|-------- led.h
|-------- led.c
|-------STM32F4xx_StdPeriph_Driver
build
Makefile
// led.h
#include <stdio.h>
#include "stm32f4xx.h"
void turnOn();
void turnOff();
// led.c
#include "led.h"
void turnOn()
{
GPIO_SetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
}
void turnOff()
{
GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
}
// main.c
#include <stdio.h>
#include "stm32f4xx.h"
#include "led.h"
...
// init gpio
...
extern void turnOn();
extern void turnOff();
...
// init sys clock
...
int main(void) {
setSysTick();
while(1)
{
//check the push button
turnOn();
Delay(500);
turnOff();
}
return 0;
}
описание файла Makefile для линковщика и компилятора
# Makefile
# STM32F4-Discovery Makefile for Mac OSX
SRCS=$(wildcard *.c)
# Add assembly source files here or use $(wildcard *.s) for all .s files
S_SRCS = CortexM4asmOps.s
# Project name
PROJ_NAME = test
OUTPATH = build
OUTPATH := $(abspath $(OUTPATH))
BASEDIR := $(abspath ./)
MKDIR_P = mkdir -p
###################################################
# Check for valid float argument
# NOTE that you have to run make clan after
# changing these as hardfloat and softfloat are not
# binary compatible
ifneq ($(FLOAT_TYPE), hard)
ifneq ($(FLOAT_TYPE), soft)
#override FLOAT_TYPE = hard
override FLOAT_TYPE = soft
endif
endif
###################################################
AS=$(BINPATH)arm-none-eabi-as
CC=$(BINPATH)arm-none-eabi-gcc
LD=$(BINPATH)arm-none-eabi-gcc
OBJCOPY=$(BINPATH)arm-none-eabi-objcopy
OBJDUMP=$(BINPATH)arm-none-eabi-objdump
SIZE=$(BINPATH)arm-none-eabi-size
LINKER_SCRIPT = stm32_flash.ld
CPU = -mcpu=cortex-m4 -mthumb
CFLAGS = $(CPU) -c -std=gnu99 -g -O2 -Wall
LDFLAGS = $(CPU) -mlittle-endian -mthumb-interwork -nostartfiles -Wl,--gc-sections,-Map=$(OUTPATH)/$(PROJ_NAME).map,--cref --specs=nano.specs
ifeq ($(FLOAT_TYPE), hard)
CFLAGS += -fsingle-precision-constant -Wdouble-promotion
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
else
CFLAGS += -msoft-float
endif
# Default to STM32F40_41xxx if no device is passed
ifeq ($(DEVICE_DEF), )
DEVICE_DEF = STM32F40_41xxx
endif
CFLAGS += -D$(DEVICE_DEF)
vpath %.a %.c lib
# Includes
INCLUDE_PATHS = -I$(BASEDIR)/inc -I$(BASEDIR)/lib/cmsis/stm32f4xx -I$(BASEDIR)/lib/cmsis/include -I$(BASEDIR)
INCLUDE_PATHS += -I$(BASEDIR)/lib/Conf
INCLUDE_PATHS += -I$(BASEDIR)/lib/STM32F4xx_StdPeriph_Driver/inc
INCLUDE_PATHS += -I$(BASEDIR)/lib/mylib
INCLUDE_PATHS += -I$(BASEDIR)/lib/mylib/led
# Library paths
LIBPATHS = -L$(BASEDIR)/lib/STM32F4xx_StdPeriph_Driver
# Libraries to link
LIBS = -lstdperiph -lc -lgcc -lnosys
OBJS = $(SRCS:.c=.o)
OBJS += $(S_SRCS:.s=.o)
###################################################
.PHONY: lib proj
all: dir lib proj
$(SIZE) $(OUTPATH)/$(PROJ_NAME).elf
lib:
$(MAKE) -C lib FLOAT_TYPE=$(FLOAT_TYPE) BINPATH=$(BINPATH) DEVICE_DEF=$(DEVICE_DEF) BASEDIR=$(BASEDIR)
proj: $(OUTPATH)/$(PROJ_NAME).elf
.s.o:
$(AS) $(CPU) -o $(addprefix $(OUTPATH)/, $@) $<
.c.o:
$(CC) $(CFLAGS) -std=gnu99 $(INCLUDE_PATHS) -o $(addprefix $(OUTPATH)/, $@) $<
$(OUTPATH)/$(PROJ_NAME).elf: $(OBJS)
$(LD) $(LDFLAGS) -T$(LINKER_SCRIPT) $(LIBPATHS) -o $@ $(addprefix $(OUTPATH)/, $^) $(LIBS) $(LD_SYS_LIBS)
$(OBJCOPY) -O ihex $(OUTPATH)/$(PROJ_NAME).elf $(OUTPATH)/$(PROJ_NAME).hex
$(OBJCOPY) -O binary $(OUTPATH)/$(PROJ_NAME).elf $(OUTPATH)/$(PROJ_NAME).bin
$(OBJDUMP) -S --disassemble $(OUTPATH)/$(PROJ_NAME).elf > $(OUTPATH)/$(PROJ_NAME).dis
dir:
$(MKDIR_P) $(OUTPATH)
clean:
rm -f $(OUTPATH)/*.o
rm -f $(OUTPATH)/$(PROJ_NAME).elf
rm -f $(OUTPATH)/$(PROJ_NAME).hex
rm -f $(OUTPATH)/$(PROJ_NAME).bin
rm -f $(OUTPATH)/$(PROJ_NAME).dis
rm -f $(OUTPATH)/$(PROJ_NAME).map
# Remove the following line if you don't want to clean the Libraries as well
$(MAKE) clean -C lib
flash:
st-flash write build/$(PROJ_NAME).bin 0x08000000
компилирую библиотеки
make lib
make[1]: `mylib' is up to date.
собираю бинарник
make
выдает ошибку
build/main.o: In function `main':
main.c:37: undefined reference to `turnOn'
main.c:39: undefined reference to `turnOff'
collect2: error: ld returned 1 exit status
make: *** [build/test.elf] Error 1
Если файлы из lib/mylib/led перенести в корень (на уровень, что и main.c), тогда все собирается хорошо