Undefined reference to sprintf in vtasklist

Hello,I’m new with Freertos .I want to know when the task runtime,and then I see void vTaskGetRunTimeStats( char *pcWriteBuffer ); when I define configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS both as 1 for this function to be available in FreeRTOSConfig.h,and then make run ,it will occur some errors and warnings as follow:
core/FreeRTOS/Source/tasks.c:4305:5: error: implicit declaration of function ‘sprintf’ [-Werror=implicit-function-declaration]
core/FreeRTOS/Source/tasks.c:4305:5: warning: incompatible implicit declaration of built-in function ‘sprintf’.
I verify that sprintf is declared in stdio.h of compile in toolchains ,and it include stdio.h in task.c . so I remove werrors flag,then it occured error undefined reference to sprintf in vtasklist.
I don’t know how to fix it, can anybody help me? Thanks very much.

Hello, before answering this question, what platform are you using, and which compiler do you use?

I use optee, fvp monitor , freertos kernel and gcc-linaro-6.2.1-2016.11-x86_64 for a Dual-Criticality System

Hm, I am not experienced with that platform.

But maybe this information about gcc helps:


It says that sprintf is a built-in function, “unless -fno-builtin is specified (or -fno-builtin-function is specified for an individual function)”.

Still strange: even when sprintf() is a built-in function, stdio.h should provide a proper declaration.

I think there is something broken with your build settings i.e. compiler / linker flags.
Assuming your gcc-linaro toolchain is otherwise fine and provides standard sprintf support.
Did you properly specify the -specs option to select the desired libc variant (in your Makefile) ?

I was going to say this was the second report of this problem in a week - but then realised both support threads were from the same person.

In any case, sprintf() comes from stdio.h, and if you have configUSE_STATS_FORMATTING_FUNCTIONS defined, that is included here: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/V10.3.1-kernel-only/tasks.c#L56 - so this does appear to be a quirk of your build rather than a FreeRTOS issue.

One thing to note, a freestanding environment, like most embedded systems is NOT required to provide sprintf(), so it is possible that stdio.h doesn’t provide it (or you need to do something so that it is provided). Functions like sprintf() do tend to be provided, but the C standard doesn’t mandate it.

I think you may be right, I’m going to use another way to get task run time. Thanks so much.

I think it is possible that stdio.h doesn’t provide it or something wrong with my environment. so I’m going to use another way to get task run time .Thanks so much!

I’m sorry to create two reports about the same problem and thanks so much for your help.