Topic : I have a problem with the malloc() function

Forum : ARM

Original Post
Post Information Post
August 27, 2008 - 3:02pm
Guest

I call the malloc() funcion in a little routine like this

#######################################
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif

ioInit();
uart1Init();

printf1("Hello!\n\r");
/* Infinite loop */

pnt = (u8*)malloc(8);

while (1)
{
}
}
#######################################

when i compile this, the linker show this message:

#######################################
Building C:\Lavoro\DDB\malloc\Malloc.rapp
Running : LD
\"C:\Programmi\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -mcpu=cortex-m3 -mthumb -Wl,-T -Xlinker "./obj\Malloc.elf.ld" -u _start -Wl,-static -Wl,--gc-sections -nostartfiles -Wl,-Map -Xlinker "./lst\Malloc.map"
c:/programmi/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.2.3/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0xc): undefined reference to `_sbrk'
collect2: ld returned 1 exit status

Build failed
#######################################

where is the problem? How you can solve? :(

Thank You

Replies
Post Information Post
+1
0
-1
August 28, 2008 - 12:16am
Guest

As it's to do with GCC and not Raisonance specifically, try looking here:
http://www.luminarymicro.com/component/option,com_joomlaboard/Itemid,92/func,view/id,2256/catid,6/

+1
0
-1
August 28, 2008 - 12:29am
Guest

You should also consider whether dynamic allocation is really necessary - or if it wouldn't be simpler and/or safer just to use static allocation.

Dynamic allocation raises a number of issues that often make it best avoided in embedded systems...

+1
0
-1
September 7, 2008 - 11:49am
Guest

Hi,
You can consider to write your own malloc function that allocate memory form the table initialized in C. It will be save because you do not need to touch starting files.

I have never done this before but it should be relatively easy.