Problem running task with function from other file


I am working on the STM F446RE board and I use the arduino framework in Visual Studio Code (c++).

My code looks as following:

#include <STM32FreeRTOS.h>
#include <task.h>
#include "tasktest.h"

void Task_Main(void *pvParameters);

void Task_Main(void *pvParameters)
  for (;;)
    TaskTest();  //<-- problem with this function

void setup()
  xTaskCreate(Task_Main, (const portCHAR *)"Task_Main", 128, NULL, 2, NULL);
  while (1)
void TaskTest() //<-- function that i want to execute


So TaskMain should execute the function TaskTest(). If this function in declared in main.cpp, then everything runs fine.

BUT: If I declare the function in tasktest.cpp (linked in tasktest.h), I get an error:

c:/users/../.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/genericSTM32F446RE/src/main.cpp.o: in function Task_Main(void*):
main.cpp:(.text._Z9Task_MainPv+0x2): undefined reference to `TaskTest()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericSTM32F446RE\firmware.elf] Error 1

I tried already different things, but I can’t solve this problem. I cannot imagine, that using FreeRTOS requires me to have all functions of an huge project in main.cpp.

Do you have any ideas?

Thank you!

Not a FreeRTOS issue, looks like the issue is that you didn’t add tasktest.cpp to your project, so the compiler included the code for it.

It is important to note that including tasktest.h in a file simply informs that file that the definitions found in tasktest.h are available. The tasktest.cpp is NOT added to the project. Specifically it is not compiled and linked with the other C and CPP files. That error message is from the link informing you that a specific funciton is not found. The solution is either:

  1. Write the function in a file that is already a part of the project, or
  2. Write the function in a different file and add it to the project.
    The details of adding a function to a project depend upon your choice of tools and is out-of-scope for this forum.

Thank you for your answers.
I restructured all my files, and now it seems. To work. Indeed it was no problem on freeRTOS.

Thank you very much for your help!