Hello All, I am using LM3S811 evaluation kit and code red development tools for firmware development. Whenever i call functions atoi or atof from stdlib, linker gives following error. : In function `_sbrk_r': sbrkr.c:(.text+0x12): undefined reference to `_sbrk' collect2: ld returned 1 exit status make: *** [SHT11_Rev5oct.axf] Error 1 For this problem,I have referred link http://embdev.net/topic/129753 on this forum. As per the instructions i have edited linker script in 'standalone.o' . Also created syscalls.c and added to my project. But its unable to link; giving error 'undefined reference to `_sbrk'' My project folder is attached for ref. What could be reason? Kindly help me. Thanks in advance :-) Ameya
Ameya Hardikar wrote: > As per the instructions i have edited linker script in 'standalone.o' > . Also created syscalls.c and added to my project. But its unable to > link; giving error 'undefined reference to `_sbrk'' Because there is no function named _sbrk in it. You call it sbrk.
Ameya Hardikar, did you find the solution ? I 've got similar probleme with my compilation : // output of "make" : LD gcc/uart_check.axf /opt/CodeSourcery/arm-2009q1/bin/../lib/gcc/arm-none-eabi/4.3.3/../../.. /../arm-none-eabi/lib/thumb2/libc.a(lib_a-sbrkr.o): In function `_sbrk_r': sbrkr.c:(.text+0x12): undefined reference to `_sbrk' make: *** [gcc/uart_check.axf] Error 1 /* end of quotation */ It looks similar, true ? Any suggestion ? Jörg Wunsch, the "_sbrk" is in a library, and it is not normal that this error occur, I do not understand... Gilles Bulthé
In fact, I have this code : ==========quotation : typedef struct historyList{ char* CmdLine; int CmdSize; struct historyList* prev; struct historyList* next; } history; history* UARTHistoNew() { history* New=(history*)malloc( sizeof(history)); New->CmdLine = ""; New->CmdSize = 0; New->prev=NULL; New->next=NULL; return New; } [...] [in my main function :] static history *pHistoList=NULL; // init the histo (Normalement, ONLY ONE TIME !) : if (pHistoList==NULL) pHistoList = UARTHistoNew(); =========end of quote And the compilation pb disappears when I disable the last line ("if (pHistoList==NULL) pHistoList = UARTHistoNew()"). Can anyone help me ? Thanks in advance. Gilles.
Hi Do you want to use dynamic memory or something like that? The "newlib" provides basic functions which are part of the standard C library. You have to provide hardware close functions yourself. You can take a look at http://sourceware.org/newlib/ a search for "system calls" Cheers, Tilo
Tilo, thank you so much. I learn by your link and http://tech.dir.groups.yahoo.com/group/lpc2000/message/22018?var=1 that malloc needs dynamics library witch needs _sbrk_r, etc. So, I will use another way, with no malloc. Ex : ===quote : history* UARTHistoNew() { // history* New = (history*)malloc( sizeof(history)); history New; New.CmdLine = ""; New.CmdSize = 0; New.prev=NULL; New.next=NULL; return &New; } [etc] ===========end Correct ? I think this way will allow me to avoid using malloc and dynamic livraries... Thanks, Gilles.
Hello Gilles, Yeah i got the problem solved. But at a cost of loosing much of my code memory space. You can change c library which your project is referring. Currently you may be using newlib(none). Change this to newlib(nohost) and build your code. But then newly generated .axf will be of almost double size than previous one. Solution is to define_sbrk in your project and build it. Keil IDE provides syscall.c file with the definition of _sbrk. refer it. also check this: http://support.code-red-tech.com/CodeRedWiki/CLibrary Thank you, Ameya
Gilles Bulthé wrote: > Correct ? I think this way will allow me to avoid using malloc and > dynamic livraries... No. After the function returned, "New" does no longer exist. If the function is really called only once, you can make "New" static and it will work then.
Gilles Bulthé wrote:
> Jörg Wunsch, the "_sbrk" is in a library, ...
No, it was supposed to be in one of Ameya's source files, but he
misnamed it sbrk (rather than _sbrk), so the linker did not find
it.
Thank you to all of you. The way to change the dynamic library in order to have it for my embedded application may be too hard. So I'll give up here, after regarding this "high-level" solution. Ameya, your solution may be THE one, but for my little application, I will prefer working in static than in dynamic. More stable. And I have small memory space. Stefan, thank for your note ! For sure, I spoke to fast... (unforgivable!) Best regards, Gilles.
That's true, Jörg, I learned it after, sorry. It was a linker problem. Real Thanks to all of the reactive members of this dynamic (library ?) forum ! See you, Gilles.
Sorry if this is not related to your topic, in another thread and saw this topic was related, i just "cross-read" this thread. ;-) But maybe this might help you "http://embdev.net/topic/129607". I got the same issue and solved it in just implementing a stub function for _sbrk. I dont use dynamic memory allocation in my sourcecode, but the linker wants a regerence to _sbrk... if you dont use malloc (or equal functions) you should be safe with a stub.
Qduda, thanks for your advice :-) if I really have to use it in the future, it would help me. Well done ! Gilles.
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.