Undefined reference to _sbrk

▼魔方 西西 提交于 2019-12-02 20:52:53

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

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.

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.

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.

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

-specs=nosys.specs
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!