SDK2.2: issues with standard string functions

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

cross mob
Anonymous
Not applicable

I was stuck by the compiled errors that failed to build because of undefined reference of some common string functions.

See below capture from build.

C:\Users\alexleung\Documents\WICED\WICED-Smart-SDK-2.2.1\WICED-Smart-SDK\Wiced-Smart\spar/../../Apps/myBeacon_manage/myBeacon_manage.c:664: undefined reference to `strtok'

C:\Users\alexleung\Documents\WICED\WICED-Smart-SDK-2.2.1\WICED-Smart-SDK\Wiced-Smart\spar/../../Apps/myBeacon_manage/myBeacon_manage.c:669: undefined reference to `strtok'

C:\Users\alexleung\Documents\WICED\WICED-Smart-SDK-2.2.1\WICED-Smart-SDK\Wiced-Smart\spar/../../Apps/myBeacon_manage/myBeacon_manage.c:681: undefined reference to `strcmp'

C:\Users\alexleung\Documents\WICED\WICED-Smart-SDK-2.2.1\WICED-Smart-SDK\Wiced-Smart\spar/../../Apps/myBeacon_manage/myBeacon_manage.c:710: undefined reference to `strncpy'

makefile:152: recipe for target '../../build/myBeacon_manage-BCM920737TAG_Q32-rom-ram-Wiced-release/A_20737A1-myBeacon_manage-rom-ram-spar.elf' failed

I have included in C file

#include "stdio.h"

#include "string.h"

I am so confused since these string functions are so common and every C compiler can support them.

Please advise what I am missing and how to resolve them.

0 Likes
1 Solution
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog

I think you will find the following thread useful, along with the second thread it references: Undefined reference to standard library functions

View solution in original post

0 Likes
4 Replies
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog

I think you will find the following thread useful, along with the second thread it references: Undefined reference to standard library functions

0 Likes
Anonymous
Not applicable

Hi alexleung0316

Did you get a chance to take a look at the thread that mwf_mmfae linked?

-Kevin

0 Likes
Anonymous
Not applicable

I rewrite those string functions that are required in my application, eg for strtok, I wrote something simple and just frugal enough to do my job.

argv[0] = strtok(buffer, " ");

change to below function

// Copies a string up to the given delimeter or if NULL terminator

// is found in the Source string.

UINT8 strcpy_delimeter(char *Dest, char *Source, UINT8 Max, char Delimiter, BOOL* pParsed)

{

  UINT8 i, length=0;

  BOOL bParsed = FALSE;

  for(i=0; i<Max; i++)

    {

      if(Source == Delimiter || Source == 0)

        {

          Dest=0;

          if(Source == Delimiter)

            bParsed = TRUE;

          break;

        }

      else

        {

          Dest=Source;

          length++;

        }

    }

  if (pParsed)

    *pParsed = bParsed;

  return(length);

}

and for standard c function strncat, I simply rewrite it like

// append the first num characters of s2 to s1

char *strn_cat(char *s1, char *s2, UINT16 num)

{

  UINT16 i;

  while(*s1)

  {

    s1++;

  }

  for (i=0; i<num; i++)

  {

    if (!*s2)

      break;

    *s1++ = *s2++;

  }

  *s1 = *s2;

  return s1;

}

Anonymous
Not applicable

Thanks for sharing!

0 Likes