对 _sbrk 的未定义引用

发布于 2024-11-02 21:07:23 字数 698 浏览 5 评论 0原文

我的 _sbrk 遇到问题。在编译的链接阶段,我使用下面的命令来链接我的对象,并且我得到了对 _sbrk 的未定义引用。

arm-none-eabi-ld -static -T linkerscript.ld -o exe timer_example.o /home/ziga/projects/cs_lite/arm-none-eabi/lib/libc.a /home/ziga/projects/cs_lite/lib/gcc/arm-none-eabi/4.5.1/libgcc.a

我正在为 arm926ej-s 和 ARM 模式进行编译,所以我认为我已经选择了正确的 multilib (libc.alibgcc.a)位于文件夹 home/ziga/projects/cs_lite/arm-none-eabi/lib/ 中。

我一直在互联网上搜索 _sbrk 函数,它是某种内存管理调用,不包含在标准 C 库中,因为它依赖于微处理器。那么我必须自己编写 _sbrk 函数吗?我该怎么做?你有arm926ej-s的例子吗?编写此函数后,我打算将其编译成目标文件并将其与其他对象、库链接在一起。

I am having a problem with _sbrk. In a link phase of compilation i use below comand to link my objects and i get undefined reference to _sbrk.

arm-none-eabi-ld -static -T linkerscript.ld -o exe timer_example.o /home/ziga/projects/cs_lite/arm-none-eabi/lib/libc.a /home/ziga/projects/cs_lite/lib/gcc/arm-none-eabi/4.5.1/libgcc.a

I am compiling for arm926ej-s and in ARM mode so i think i have chosen the right multilib (libc.a and libgcc.a) which is located in folder home/ziga/projects/cs_lite/arm-none-eabi/lib/.

I have been searching internet for _sbrk function and it is some sort of a memory managment call which isnt included in standard C libraries as it is dependant on microprocessor. So do I have to write _sbrk function on my own? How do I do it? Do you have any example for arm926ej-s? After writing this function I intend to compile it into an object file and link it together with other objects, libraries.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

赴月观长安 2024-11-09 21:07:24

这有助于:

-mcpu=cortex-m4 -mthumb -specs=nano.specs -specs=nosys.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard

重要的开关“似乎”是:

-specs=nano.specs -specs=nosys.specs

This helps:

-mcpu=cortex-m4 -mthumb -specs=nano.specs -specs=nosys.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard

The important switches "seem" to be:

-specs=nano.specs -specs=nosys.specs

凉薄对峙 2024-11-09 21:07:24

我遇到了同样的问题,将它们添加到链接器标志中有所帮助:

-specs=nano.specs -specs=nosys.specs

此外,仅使用 nosys.specs 就解决了问题,但代码大小要大得多。

I was having the same problem, and adding those to the linker flags helped:

-specs=nano.specs -specs=nosys.specs

Also, just with the nosys.specs fixed the issue, but the code size was a lot bigger.

鼻尖触碰 2024-11-09 21:07:24

使用 VisualGDB(使用 GCC)和 Nanolib,我必须添加链接器标志

-specs=nosys.specs

with visualgdb (using gcc), and nanolib, I had to add the linker flag

-specs=nosys.specs
回眸一笑 2024-11-09 21:07:24

该问题与 _sbrk 本身无关,而是您尝试绕过编译器驱动程序直接调用链接器。相反,使用 gcc 命令调用链接器,并使用 -Wl,-linkeroptionhere 语法将额外选项传递给链接器。

如果您必须自己调用链接器,一种可能的解决方案是尝试在命令行末尾再次重复 libc.alibgcc.a 。您还可以使用一些“作为组”链接器选项来实现此目的,但我现在还不知道。

The problem has little to do with _sbrk itself, but rather your attempt to invoke the linker directly, bypassing the compiler driver. Instead, use the gcc command to invoke the linker and the -Wl,-linkeroptionhere syntax to pass extra options to the linker.

One possible solution, if you must invoke the linker yourself.. Try repeating both libc.a and libgcc.a a second time at the end of the command line. There's also some "as group" linker option you could use to achieve this but I don't know it right off.

迟到的我 2024-11-09 21:07:24

最近我也遇到了这个(再次)。对我来说最简单的解决方案是将“malloc”和“free”api提供/重定向到我正在构建应用程序的SDK中可用的api。

基本上发生这种情况是因为链接时缺少内存管理 API。就像上面的答案提到的那样,这里并不是特别缺少 _sbrk 。 brk/sbrk 系统调用内部用于堆管理。因此,当涉及到内存管理 API 时,_sbrk 就缺失了。

我注意到添加 -lnosys (即 libnosys.a)在某些集成中也有一定程度的帮助。

recently I also ran into this(again). the easiest solution which worked for me was to provide/redirect "malloc" and "free" apis to the one available from the SDK on which I was building my application.

Basically it happens because of mem management apis missing while linking. like the above answer mentions its not that _sbrk is specifically missing here. brk/sbrk syscall intenrally is used for heap management. hence the _sbrk ,missing link when it comes to mem management apis.

I noticed that adding -lnosys (i.e libnosys.a) also helped a this to a degree in some integrations.

幸福不弃 2024-11-09 21:07:24

我解决了这个问题并将在这里发布解决方案,以便我回馈社区。函数 _sbrk 位于 ARM 的 NXP CDL 包内。软件包可供下载(链接适用于所有还不知道这一点的人) 此处 在子文件夹 CDL_v005/csps/lpc313x/bsps/ea3131/source 中,您将找到名为libnosys_gnu.c 应该添加到项目中并编译为目标文件,然后与其他对象和库一起链接到可执行文件。

最美好的祝愿和巨大的成功。

I solved this problem and will post solution here so i give something back to comunity. The function _sbrk is located inside NXP CDL package for ARM. Package is available for download (link is for all who dont know this already) here in subfolder CDL_v005/csps/lpc313x/bsps/ea3131/source you will find source file named libnosys_gnu.c which should be added to the project and compiled to object file and after that linked to executable file alongside other objects and libraries.

Best wishes and a lot of success.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文