I have a project by use STM32F103C8T6. It has tree:
__main.c
|__main.h
|__led.c
|__led.h
|__stm32f1xx_startup.c
|__Makefile
I'm using arm-none-eabi-gcc to compile this project. Makefile
as below:
CC = arm-none-eabi-gcc
MARCH = cortex-m3
CFLAGS = -c -mcpu=$(MARCH) -mthumb -std=gnu11 -Wall -O0
RM = rm -rf
OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
INCS = $(wildcard *.h)
all: $(OBJS)
$(CC) $(CFLAGS) $< -o $@
%.o: %.c %.h
$(CC) $(CFLAGS) $< -o $@
.PHONY: clean
clean:
$(RM) *.o all
When I run make
command by Terminal of VS Code,it's not generate execute file and has a warning like this:
minh@Minh:~/Workspaces/Stm32/BeraMetal$ make
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0 main.c -o main.o
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0 -c -o stm32f1xx_startup.o stm32f1xx_startup.c
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0 led.c -o led.o
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -std=gnu11 -Wall -O0 main.o -o all
arm-none-eabi-gcc: warning: main.o: linker input file unused because linking not done
Please tell me how I can fix it? Thank advance.
CodePudding user response:
You use the same flags for both compilation into object files, as when you attempt to link the object files together.
The problem is that the linking command will then use the -c
flags, which is used to build object files.
You need to separate compilation and linker flags. Or at least not specify -c
in CFLAGS
.
CodePudding user response:
how I can fix it?
Don't pass -c
to linking stage. Also, you have to pass all objects to the linker.
CFLAGS = -mcpu=$(MARCH) -mthumb -std=gnu11 -Wall -O0
all: $(OBJS)
$(CC) $(CFLAGS) $^ -o $@
%.o: %.c %.h
$(CC) $(CFLAGS) -c $< -o $@
Consider using something newer than grandpa Make - CMake
Scons
Meson
.