首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cortex-M3 (EFM32GG) -ARM-Nano的GCC链接器标志

Cortex-M3 (EFM32GG) -ARM-Nano的GCC链接器标志
EN

Stack Overflow用户
提问于 2020-10-20 22:00:32
回答 1查看 408关注 0票数 0

我分析了Silicon (面向微控制器的Silicon Labs的Eclipse IDE变体)生成的一个项目。

我使用了一个基于arm-none-eabi-gcc工具链的ASM/C/C++项目的默认设置。

对于G++-Linker-Flags,他们做了一些对我来说非常奇怪的事情:他们打算链接到newlib-nano (所以是标准库的小版本)。

然而,通常你需要决定你是否打算使用重定向,从而链接到nosys.specs,这也会使你的二进制文件更大,或者是最简单的nano.specs。

然而,他们确实列出了两个选项,这对我来说是没有意义的。所以我检查了另一个项目设置(这是在STM32的CM3上),他们显然也是这样做的。为什么会这样呢?

如果我不打算使用重定向(比如文件系统、printf/_write等),我需要列出nosys.specs吗?

附加问题:这些标志的顺序重要吗?或者这只是您想要添加的所有选项的列表?

代码语言:javascript
复制
-g3 -gdwarf-2 -mcpu=cortex-m3 -mthumb -T "${BuildArtifactFileBaseName}.ld" --specs=nosys.specs -Xlinker --gc-sections -Xlinker -Map="${BuildArtifactFileBaseName}.map" --specs=nano.specs
EN

回答 1

Stack Overflow用户

发布于 2020-10-21 09:18:54

然而,他们确实列出了两个选项,这对我来说是没有意义的。

这很有意义。在没有nosys的情况下,您需要提供大量函数的定义,或者使用其他库,例如用于半主机。

简单的例子:(main.c就是hello world程序)

代码语言:javascript
复制
piotr@PiotrLaptop02:~$ arm-none-eabi-gcc --specs=nano.specs main.c
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-exit.o): in function `exit':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:64: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-sbrkr.o): in function `_sbrk_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/sbrkr.c:51: undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-writer.o): in function `_write_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/writer.c:49: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-closer.o): in function `_close_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/closer.c:47: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-fstatr.o): in function `_fstat_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/fstatr.c:55: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-isattyr.o): in function `_isatty_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/isattyr.c:52: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-lseekr.o): in function `_lseek_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/lseekr.c:49: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc_nano.a(lib_a-readr.o): in function `_read_r':
/build/newlib-CVVEyx/newlib-3.3.0/build_nano/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/readr.c:49: undefined reference to `_read'
collect2: error: ld returned 1 exit status
piotr@PiotrLaptop02:~$ arm-none-eabi-gcc --specs=nano.specs --specs=nosys.specs main.c
piotr@PiotrLaptop02:~$  

如你所见,如果没有nosys,它将无法链接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64446774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档