我正在为 Cortex-A8 处理器编写软件,我必须编写一些 ARM 汇编代码来访问特定的寄存器。我正在使用 gnu 编译器和相关工具链,这些工具安装在 Ubuntu 的处理器板上(飞思卡尔 i.MX515)。我使用 WinSCP 和 PuTTY 终端从我的主机 PC(Windows)连接到它。
像往常一样,我从一个具有main.c和functions.s的简单 C 项目开始。我使用GCC编译main.c ,使用as组装functions.s并再次使用GCC链接生成的目标文件,但在此过程中出现奇怪的错误。
一个重要的发现——
同时,我发现我的汇编代码可能有一些问题,因为当我使用命令单独组装它as -o functions.o functions.s
并尝试使用命令运行生成的functions.o./functions.o
时,bash shell无法将此文件识别为可执行文件(在按下选项卡功能时.o 没有被选中/PuTTY 没有突出显示文件)。
谁能建议这里发生了什么?在链接过程中,我必须向 GCC 发送任何特定选项吗?我看到的错误很奇怪,超出了我的理解,我不明白 GCC 指的是什么。
我在这里粘贴 main.c、functions.s、Makefile 和错误列表的内容。
请帮忙!!!
按照这里的人的建议编辑 makfile 后包含的最新错误 -
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
主程序
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
函数.s
* 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
生成文件
all: hello
hello: main.o functions.o
gcc hello -o main.o functions.o
- 在stackoverflow的人在这里提出建议后,你好被包含在这里,但问题仍然存在,我仍然遇到同样的错误。
main.o: main.c
gcc -c -mcpu=cortex-a8 main.c
functions.o: functions.s
as -mcpu=cortex-a8 -o functions.o functions.s
错误
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