为 ARM 处理器编译基本 C 文件 [英] Compiling basic C file for the ARM processor

查看:29
本文介绍了为 ARM 处理器编译基本 C 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GCC 工具链的 Yagarto 重新编译.我正在尝试编译这个简单的程序以获得 .elf 可执行文件:

I am using the Yagarto recompilation of the GCC toolchain. I am trying to compile this simple program to get an .elf executable:

int main(void)
{
    return(0);
}

当输入命令 arm-none-eabi-gcc main.c 我收到错误信息

When typing the command arm-none-eabi-gcc main.c I get the error message

c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o):在函数 exit' 中:C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.19.0/newlib/libc/stdlib/exit.c:65:对_exit' collect2 的未定义引用:ld 返回 1 个退出状态

c:/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): In function exit': C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.19.0/newlib/libc/stdlib/exit.c:65: undefined reference to_exit' collect2: ld returned 1 exit status

我做错了什么?

推荐答案

Newlib 要求您定义一个 _exit 符号.您可能还必须提供其他符号才能使 newlib 工作:http://sourceware.org/newlib/libc.html#Stubs

Newlib requires you to define an _exit symbol. There might also be other symbols that you have to provide to make newlib work: http://sourceware.org/newlib/libc.html#Stubs

这样的事情应该就足够了(假设您正在为微控制器编译,当您有操作系统时不要这样做):

Something like this should be sufficient (assuming you are compiling for a microcontroller, don't do this when you have an OS):

.globl _exit
_exit:
    b     . // Loop until reset

或者在 C:

void _exit(void) {
    while(1) {
        // Loop until reset
    }
}

顺便说一句:你可能想在旋转之前禁用中断.

BTW: you might want to disable interrupts before spinning.

也许有一点额外的信息.Yagarto 包含 Newlib 作为 libc,它是一个提供printf()malloc() 等函数的库.但是,它不知道如何将字符发送到屏幕或控制台(在 printf 的情况下),或者在调用 abort()exit() 时如何退出.因此,Newlib 要求您提供一些基本功能的实现,具体取决于您使用的 Newlib 的功能.

Maybe a litte bit extra information. Yagarto includes Newlib as libc, which is a library providing functions like printf(), malloc(), etc. However, it cannot know how to send a character to a screen or console (in case of printf), or how to exit in case you call abort() or exit(). Therefore, Newlib requires you to provide implementations of a few basic function, depending on what functionality of Newlib you use.

这篇关于为 ARM 处理器编译基本 C 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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