Initializing an array causes a "undefined reference to memset"

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

This is what I'm doing:

#include "string.h"

#include "stdio.h"

UINT8 array[62];

  UINT8 settings[] = {0x08,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x1A,0xD8,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B};

  memcpy(array,settings,sizeof(settings));

And I get......:

C:\WICED\WICED-Smart-SDK-2.2.0\WICED-Smart-SDK\Wiced-Smart\spar/../../Apps/genoaV1_0/as3911Testing.c:15: undefined reference to `memset' 

Thoughts? 

0 Likes
1 Solution

memset is a #define to __eabi_memset in spar_utils.h so when writing your own code it will work because __eabi_memset will be called.

#define memset(dest,val,len) __aeabi_memset(dest,len,val)

But gcc is using memset calls to initialise structures/arrays and since memset is not "defined", that will fail.

There was this issue with memcpy but they fixed it in the 2.1.1 SDK by defining memcpy in the patch.elf file but memset hasen't been.

The easy fix is to implement your own memset function

void __aeabi_memset(void *dest, size_t n, int c);
void*  memset(void *dest, int c, size_t n)
{
     __aeabi_memset(dest, n, c);
     return dest;
}

View solution in original post

2 Replies
Anonymous
Not applicable

By the way, to make it clear, it's the array initialization that causes the compile error.  When I do this:

#include "string.h"

#include "stdio.h"

UINT8 array[62];

UINT8 settings[62];

memcpy(array,settings,sizeof(settings));

There is no error.  This seems like a compiler bug to me. 

0 Likes

memset is a #define to __eabi_memset in spar_utils.h so when writing your own code it will work because __eabi_memset will be called.

#define memset(dest,val,len) __aeabi_memset(dest,len,val)

But gcc is using memset calls to initialise structures/arrays and since memset is not "defined", that will fail.

There was this issue with memcpy but they fixed it in the 2.1.1 SDK by defining memcpy in the patch.elf file but memset hasen't been.

The easy fix is to implement your own memset function

void __aeabi_memset(void *dest, size_t n, int c);
void*  memset(void *dest, int c, size_t n)
{
     __aeabi_memset(dest, n, c);
     return dest;
}