我正在为 Cortex-A8 处理器编写软件,并且必须编写一些 ARM 汇编代码来访问特定寄存器。我正在使用 GNU 编译器和相关工具链;这些工具安装在带有 Ubuntu 的处理器板 (Freescale i.MX515) 上。我使用 WinSCP 和 PuTTY 终端从我的主机 PC (Windows) 与其建立连接。
像往常一样,我从一个简单的 C 项目开始main.c and 函数. I compilemain.c 使用GCC, assemble函数使用as and link再次使用生成的目标文件GCC,但在此过程中我遇到了奇怪的错误。
一个重要发现——
同时,我发现我的汇编代码可能存在一些问题,因为当我使用命令单独汇编它时as -o functions.o functions.s
并尝试运行生成的函数.o using ./functions.o
命令时,Bash shell 无法将此文件识别为可执行文件(按选项卡功能时。o 未被选中/PuTTY 未突出显示该文件)。
谁能建议这里发生了什么?有没有我必须发送给 GCC 的具体选项在链接过程中?我看到的错误很奇怪,超出了我的理解,我不明白 GCC 指的是什么。
我在这里粘贴了 main.c、functions.s、Makefile 的内容和错误列表。
请帮助!!!
**按照此处建议编辑 makefile 后包含的最新错误 **
ubuntu@ubuntu-desktop:~/Documents/Project/Others/helloworld$ make
gcc -c -mcpu=cortex-a8 main.c
as -mcpu=cortex-a8 -o functions.o functions.s
gcc -o hello main.o functions.o
functions.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:init.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [hello] Error 1
main.c
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
函数
* Main program */
.equ STACK_TOP, 0x20000800
.text
.global _start
.syntax unified
_start:
.word STACK_TOP, start
.type start, function
start:
movs r0, #10
movs r1, #0
.end
Makefile
all: hello
hello: main.o functions.o
gcc hello -o main.o functions.o
-- hello 是在 Stack Overflow 的人建议后添加到这里的,但问题仍然存在;我仍然遇到同样的错误。
main.o: main.c
gcc -c -mcpu=cortex-a8 main.c
functions.o: functions.s
as -mcpu=cortex-a8 -o functions.o functions.s
Errors
ubuntu@ubuntu-desktop:~/Documents/Project/Others/helloworld$ make
gcc -c -mcpu=cortex-a8 main.c
as -mcpu=cortex-a8 -o functions.o functions.s
gcc -o main.o functions.o
functions.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:init.c:(.text+0x0): first defined here
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o: In function `_start':
init.c:(.text+0x30): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [hello] Error 1