更多GCC链接时间问题:对main的未定义引用

我正在为Cortex-A8处理器编写软件,我必须编写一些ARM汇编代码来访问特定的寄存器。 我正在使用gnu编译器和相关工具链,这些工具安装在带有Ubuntu的处理器板(Freescale i.MX515)上。 我使用WinSCP和PuTTY终端从我的主机PC(Windows)连接到它。

像往常一样,我开始使用一个带有main.cfunctions.s的简单C项目。 我使用GCC 编译 main.c,使用as 汇编 functions.s并再次使用GCC 链接生成的目标文件,但在此过程中我得到了奇怪的错误。

一个重要发现 –

同时,我发现我的汇编代码可能有一些问题,因为当我使用命令as -o functions.o functions.s单独组装它时,尝试运行生成的函数。使用./functions.o命令,bash shell无法将此文件识别为可执行文件(在按Tab键function时。未选中/ 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 

main.c中

 #include  #include  int main(void) { puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ return EXIT_SUCCESS; } 

functions.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 

Makefile文件

 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 

在makefile中:

 hello: main.o functions.o gcc -o main.o functions.o 

应该:

 hello: main.o functions.o gcc -o hello main.o functions.o 

就目前而言,您将链接functions.o,但不是main.o,并生成一个名为main.o的输出可执行文件,它将覆盖您现有的main.o.

不能

 hello: main.o functions.o gcc -o main.o functions.o 

 hello: main.o functions.o gcc -o hello main.o functions.o 

正如Bigbohne所说,gcc正试图在标准运行时库中进行链接。 尝试将-nostdlib选项添加到gcc调用中:

 gcc -nostdlib -o hello main.o functions.o 

我认为这与gcc最后链接的Runtime库有关。

这个图书馆里已经有了一个“_start”。

我认为你必须编译没有“标准库”。 但是你没有printf,getchar和所有其他有用的东西。