Are sprintf(), malloc() ... available in WICED BT?

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

cross mob
StN__1917156
Level 4
Level 4
25 replies posted 10 replies posted 5 replies posted

Is there any additional libraries or flags that have to put in the make file or whatever else needed to make this very basic C functionality to work?

I tried both

#include "stdio.h"

#include <stdio.h>

But always got:

D:\WICED-Studio-6.2\SDK\20719-B1_Bluetooth\WICED/../apps/w191/spp1/spp.c:517: undefined reference to `sprintf'

Tracking it back to declaration in stdio.h I've got:

int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)

               _ATTRIBUTE ((__format__ (__printf__, 2, 3))));

Thanks

P.S. Same story is and with stdlib.h and  malloc() and free():

D:\WICED-Studio-6.2\SDK\20719-B1_Bluetooth\WICED/../apps/w191/spp1/spp.c:520: undefined reference to `malloc'

D:\WICED-Studio-6.2\SDK\20719-B1_Bluetooth\WICED/../apps/w191/spp1/spp.c:521: undefined reference to `free'

0 Likes
1 Solution
SheetalJ
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 500 likes received

Hi StN._1917156​,

The sprintf, malloc and free functions are not implemented in CYW20719B1 firmware.

However, instead of sprintf, you can use snprintf in following way:

char name[20];

int a=1;

snprintf(name, sizeof(name), "Try-%d", a);

WICED_BT_TRACE ("%s", name);

For malloc, free operations, you can use WICED APIs. Please refer wiced_memory.h for more details.

View solution in original post

0 Likes
1 Reply
SheetalJ
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 500 likes received

Hi StN._1917156​,

The sprintf, malloc and free functions are not implemented in CYW20719B1 firmware.

However, instead of sprintf, you can use snprintf in following way:

char name[20];

int a=1;

snprintf(name, sizeof(name), "Try-%d", a);

WICED_BT_TRACE ("%s", name);

For malloc, free operations, you can use WICED APIs. Please refer wiced_memory.h for more details.

0 Likes