我想编译和汇编,然后链接一些源文件。据我所知,它没有告诉链接器使用VPATH中的路径,直到我第二次运行它。 这里的Makefile文件:第二次运行时只使用VPATH?
#Makefile for SWS ARMKern
CC=arm-linux-gnueabi-gcc
LD=arm-linux-gnueabi-ld
CFLAGS=-g -Wall -Wextra -std=gnu11 -ffreestanding -march=armv6 -msoft-float -fPIC -mapcs-frame
LDFLAGS=-N -Ttext=0x10000
HWDEF=versatilepb #The set of hardware quirks to use.
#Paths
VPATH=src/:obj/
CINC=-Isrc/include/
kernel.elf: bootstrap.o kernel.o
.PHONY: clean test
clean:
rm -f obj/*.o elf/*.elf
test:
qemu-system-arm -M versatilepb -cpu arm1176 -nographic -soundhw none -kernel elf/kernel.elf
.SUFFIXES: .s .o .c .elf
.o.elf:
$(LD) $(LDFLAGS) -o elf/[email protected] $^
.c.o:
$(CC) $(CFLAGS) $(CINC) -DHWCLASS=$(HWDEF) -o obj/[email protected] -c $^
.s.o:
$(CC) $(CFLAGS) $(CINC) -DHWCLASS=$(HWDEF) -o obj/[email protected] -c $^
这是发生了什么:
> ls
elf isosrc Makefile Makefile~ obj README.md README.md~ src
> make kernel.elf
arm-linux-gnueabi-gcc -g -Wall -Wextra -std=gnu11 -ffreestanding -march=armv6 -msoft-float -fPIC -mapcs-frame -Isrc/include/ -DHWCLASS=versatilepb -o obj/kernel.o -c src/kernel.c
arm-linux-gnueabi-gcc -g -Wall -Wextra -std=gnu11 -ffreestanding -march=armv6 -msoft-float -fPIC -mapcs-frame -Isrc/include/ -DHWCLASS=versatilepb -o obj/bootstrap.o -c src/bootstrap.s
arm-linux-gnueabi-ld -N -Ttext=0x10000 -o elf/kernel.elf kernel.o bootstrap.o
arm-linux-gnueabi-ld: cannot find kernel.o: No such file or directory
arm-linux-gnueabi-ld: cannot find bootstrap.o: No such file or directory
Makefile:26: recipe for target 'kernel.elf' failed
make: *** [kernel.elf] Error 1
> make kernel.elf
arm-linux-gnueabi-ld -N -Ttext=0x10000 -o elf/kernel.elf obj/kernel.o obj/bootstrap.o
我敢肯定,这只是一个问题,我的Makefile,但我很为难。我如何确保链接器使用VPATH路径?甚至只是迫使它在obj/
谢谢!
.SUFFIXES已过时,它定义了处理文件的顺序。在/ SUFFIXES语句中,它表示在.c文件之前处理.o文件。这将是一个问题。 make中的默认.SUFFIXES正确列出了所有文件名的结尾,所以.SUFFIXES不应该在'本地'makefile中 – user3629249