- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you will find the following thread useful, along with the second thread it references: Undefined reference to standard library functions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you will find the following thread useful, along with the second thread it references: Undefined reference to standard library functions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for sharing!