更多GCC链接时的问题:未定义引用主 [英] More GCC link time issues: undefined reference to main

查看:508
本文介绍了更多GCC链接时的问题:未定义引用主的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Cortex-A8处理器编写软件,我必须写一些ARM汇编code访问特定的寄存器。我正在使用GNU编译器和相关的工具链,这些工具都安装在处理器板(飞思卡尔的i.MX515)与Ubuntu。我让使用WinSCP赋予和终端的PuTTY我的主机PC(Windows)中到它的连接。

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

的一个重要发现 -

同时,我发现我的组装code可能有一些问题,因为当我单独使用命令进行组装作为-o functions.o functions.s 并尝试运行生成的 functions.o ./ functions.o 命令,bash shell中未能识别此文件作为一个可执行文件(上pressing标签functions.o是没有得到选中/腻子不突出文件)。

任何人都可以提出发生了什么吗?是否有任何的具体的我都送在链接过程中的选项,海湾合作委员会?我看到的错误是奇怪的,我不明白,我不明白什么海合会所指。

我在这里贴的main.c中的内容,functions.s,Makefile文件和错误列表。

帮助,请!

最新的错误包括后makfile被编辑由人在这里的建议 -

  Ubuntu的@ Ubuntu的桌面:〜/文档/项目/其它/ $的HelloWorld化妆
GCC -c -mcpu = Cortex-A8的main.c中
作为-mcpu = Cortex-A8的-o functions.o functions.s
GCC -o你好main.o中functions.o
functions.o:在功能`_start:
(+的.text为0x0):`_start的多重定义
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:init.c:(.text+0x0):首先这里定义
collect2:劳工处返回1退出状态
使:*** [你好]错误1


的main.c

 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;诠释主要(无效){    看跌期权(!!!你好世界!!!); / *打印!!!你好!!!世界* /
    返回EXIT_SUCCESS;
}

functions.s

  *主程序* /
    .EQU STACK_TOP,0x20000800
    。文本
    。全球_start
    .syntax统一_开始:
    .word STACK_TOP,开始
    .TYPE启动,功能开始:
    MOVS R0,#10
    MOVS R1,#0
    。结束

的Makefile

 所有:你好您好:main.o中functions.o
    GCC你好-o main.o中functions.o

- 在这里被列入你好建议后,在这里通过计算器的家伙,但问题仍然存在,我仍然得到同样的错误。

  main.o中:main.c中
    GCC -c -mcpu = Cortex-A8的main.c中functions.o:functions.s
    作为-mcpu = Cortex-A8的-o functions.o functions.s

错误

  Ubuntu的@ Ubuntu的桌面:〜/文档/项目/其它/ $的HelloWorld化妆
GCC -c -mcpu = Cortex-A8的main.c中
作为-mcpu = Cortex-A8的-o functions.o functions.s
GCC -o main.o中functions.o
functions.o:在功能`_start:
(+的.text为0x0):`_start的多重定义
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:init.c:(.text+0x0):首先这里定义
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:在功能`_start:
。INIT.C :(文字+的0x30):未定义引用'主'
collect2:劳工处返回1退出状态
使:*** [你好]错误1


解决方案

在生成文件:

 你好:main.o中functions.o
    GCC -o main.o中functions.o

应该是:

 你好:main.o中functions.o
    GCC -o你好main.o中functions.o

既然这样,你要链接functions.o,但并不main.o中,并会生成一个名为main.o中输出可执行,这是覆盖现有main.o.

I'm writing software for a Cortex-A8 processor and I have to write some ARM assembly code to access specific registers. I'm making use of the gnu compilers and related tool chains, these tools are installed on the processor board(Freescale i.MX515) with Ubuntu. I make a connection to it from my host PC(Windows) using WinSCP and the PuTTY terminal.

As usual I started with a simple C project having main.c and functions.s. I compile the main.c using GCC, assemble the functions.s using as and link the generated object files using once again GCC, but I get strange errors during this process.

An important finding -

Meanwhile, I found out that my assembly code may have some issues because when I individually assemble it using the command as -o functions.o functions.s and try running the generated functions.o using ./functions.o command, the bash shell is failing to recognize this file as an executable(on pressing tab functions.o is not getting selected/PuTTY is not highlighting the file).

Can anyone suggest whats happening here? Are there any specific options I have to send, to GCC during the linking process? The errors I see are strange and beyond my understanding, I don't understand to what the GCC is referring.

I'm pasting here the contents of main.c, functions.s, the Makefile and the list of errors.

Help, please!!!

Latest errors included after the makfile was edited as suggested by guys here -

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;
}

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

-- hello was included here after suggested here by guys at stackoverflow, but the problem still persists, I still get the same errors.

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

解决方案

In the makefile:

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

should be:

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

As it stands, you are linking functions.o, but not main.o, and producing an output executable called main.o, which is overwriting your existing main.o.

这篇关于更多GCC链接时的问题:未定义引用主的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆