使用Makefile進行GCC編譯報錯問題解決方法
匯編代碼如下:
_start:
ldr r0, =0x11111111
ldr r1, =0xE0200240
str r0, [r1]
ldr r0, =0x0
ldr r1, =0xE0200244
str r0, [r1]
flag:
b flag
Makefile代碼如下:
led.bin: start.o
arm-linux-ld -Ttext 0x0 -o led.elf $^
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led_elf.dis
gcc mkv210_image.c -o mkx210
./mkx210 led.bin 210.bin
%.o : %.S
arm-linux-gcc -o $@ $< -c
%.o : %.c
arm-linux-gcc -o $@ $< -c
clean:
rm *.o *.elf *.bin *.dis mkx210 -f
進行make,但是報錯,如下:
as -o start.o start.s
start.s: Assembler messages:
start.s:2: Error: no such instruction: `ldr r0,=0x11111111'
start.s:3: Error: no such instruction: `ldr r1,=0xE0200240'
start.s:4: Error: invalid char '[' beginning operand 2 `[r1]'
start.s:6: Error: no such instruction: `ldr r0,=0x0'
start.s:7: Error: no such instruction: `ldr r1,=0xE0200244'
start.s:8: Error: invalid char '[' beginning operand 2 `[r1]'
start.s:10: Error: no such instruction: `b flag'
make: *** [start.o] Error 1
是什麼原因呢?
Makefile中的依賴也沒有寫錯,匯編也沒有錯,為什麼編譯不了而報錯呢?原因很傻瓜,就是因為start.s寫錯了,後綴名要大寫,寫成:start.S,就可以編譯成功了。
arm-linux-gcc -o start.o start.S -c
arm-linux-ld -Ttext 0x0 -o led.elf start.o
arm-linux-ld: warning: cannot find entry symbol _start; defaulting to 00000000
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led_elf.dis
gcc mkv210_image.c -o mkx210
./mkx210 led.bin 210.bin