I've recently decided to start using makefiles instead of typing each command into a bash file but I've come across a problem while trying to compile while using one.
I'm trying to compile a few C and assembly files but keep getting this error. I've triple checked all the files and there is nothing wrong with them, so I'm assuming it's my makefile.
Here's the error that I'm getting:
…
i686-elf-gcc -T linker.ld -o bin/kernel.bin -ffreestanding -O2 -nostdlib src/boot.o \
src/gdt.o src/cgdt.o src/kernel.o -lgcc
src/cgdt.o: In function `gdt_set_gate':
cgdt.c:(.text+0x0): multiple definition of `gdt_set_gate'
src/gdt.o:gdt.c:(.text+0x0): first defined here
src/cgdt.o: In function `gdt_install':
cgdt.c:(.text+0x70): multiple definition of `gdt_install'
src/gdt.o:gdt.c:(.text+0x70): first defined here
src/gdt.o: In function `gdt_install':
gdt.c:(.text+0x17a): undefined reference to `gdt_flush'
src/cgdt.o: In function `gdt_install':
cgdt.c:(.text+0x17a): undefined reference to `gdt_flush'
collect2: error: ld returned 1 exit status
Makefile:17: recipe for target 'link' failed
make: *** [link] Error 1
And here's the makefile:
CC=i686-elf-gcc
AS=i686-elf-as
LINKER=i686-elf-gcc
CFLAGS=-std=gnu99 -ffreestanding -O2 -Wall -Wextra -I./src/include
LDFLAGS=-T linker.ld
C_SOURCES = $(shell ls src/*.c)
ASM_SOURCES = $(shell ls src/*.s)
OBJECTS = $(ASM_SOURCES:.s=.o) $(C_SOURCES:.c=.o)
all: $(OBJECTS) link
clean:
-rm ./src/*.o
link:
$(LINKER) $(LDFLAGS) -o bin/kernel.bin -ffreestanding -O2 -nostdlib $(OBJECTS) -lgcc
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
.s.o:
$(AS) $< -o $@