这是我编译器的Makefile。
CC = arm-none-eabi-gcc
AS = arm-none-eabi-as
LD = arm-none-eabi-ld
OD = arm-none-eabi-objdump
CFLAGS = -g -c -O1 -mcpu=cortex-m0 -mthumb
AFLAGS = -g -c -mcpu=cortex-m0 -mthumb
LDFLAGS = -g -mcpu=cortex-m0 -mthumb --specs=rdimon.specs -lc -lrdimon
ODFLAGS = -d
all: HW1.elf
test: HW1.elf
@ echo "...copying"
qemu-system-arm -machine versatilepb -cpu cortex-m3 -nographic -monitor null -serial null -semihosting -k\
ernel HW1.elf
HW1.elf: test.o t1.o
$(CC) $(LDFLAGS) test.o t1.o -o HW1.elf
test.o: test.c t1.o
@ echo ".compiling"
$(CC) $(CFLAGS) test.c t1.o -o test.o
t1.o: t1.s
@ echo ".assembling"
$(AS) $(AFLAGS) t1.s -o t1.o
clean:
rm -rf t1.o test.o HW1.elf
当我make all
时,我得到了
.assembling
arm-none-eabi-as -g -c -mcpu=cortex-m0 -mthumb t1.s -o t1.o
.compiling
arm-none-eabi-gcc -g -c -O1 -mcpu=cortex-m0 -mthumb test.c t1.o -o test.o
arm-none-eabi-gcc: warning: t1.o: linker input file unused because linking not done
arm-none-eabi-ld -g -mcpu=cortex-m0 -mthumb --specs=rdimon.specs -lc -lrdimon test.o -o HW1.elf
arm-none-eabi-ld: unrecognised emulation mode: thumb
Supported emulations: armelf
make: *** [HW1.elf] Error 1
我查看了StackOverflow上的numberly collect2错误,发现有一个函数未定义或被错误标记。
我已进入〜/ .bashrc文件中的目录来调用arm-none-eabi库函数。我知道这个错误与t1.s和/或test.c文件无关,而只是与处理我的makefile的不正确的符号有关,但我对于我做错了什么感到迷茫。我知道这是test.o
的内容。
我将提供test.c和t1.s,以防它们出现问题。
test.c的
include <stdio.h>
extern int inc(int);
#define RED_COUNT 5
#define YELLOW_COUNT 2
#define GREEN_COUNT 5
enum light_states {RED, YELLOW, GREEN};
static int state = RED;
void stop_light () {
static int state_counter = 0;
switch (state) {
case RED:
printf("RED\n");
if (++state_counter >= RED_COUNT) {
state_counter = 0;
state = GREEN;
}
break;
case GREEN:
printf("GREEN\n");
if (++state_counter >= GREEN_COUNT) {
state_counter = 0;
state = YELLOW;
}
break;
case YELLOW:
printf("YELLOW\n");
if (++state_counter >= YELLOW_COUNT) {
state_counter = 0;
state = RED;
}
break;
default:
state = RED;
state_counter = 0;
break;
}
}
main(){
int i;
while (i < 36) {
stop_light();
i = inc(i);
}
}
t1.s
.text
.syntax unified
.thumb
.global inc
.type inc, %function
inc:
adds r0,r0,#1
bx lr
编辑1: 更新了缺少的'-c',现在收到关于LD的新错误。
编辑2: 更新了LD错误。现在一切都已修好,答案非常有帮助!