# Undefined reference to xTaskCreate()

**URL:** <https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342>\
**Category:** Kernel\
**Created:** [August 28, 2021, 6:49am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342 "2021-08-28T06:49:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinceab](https://avatars.discourse-cdn.com/v4/letter/v/c5a1d2/32.png) [@vinceab](https://forums.freertos.org/u/vinceab)\
**Post date:** [August 28, 2021, 6:49am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/1 "2021-08-28T06:49:30Z")

</div>

I’m using PlatformIO to run a FreeRTOS code on the Nexys RISC-V framework. Shown below is the platformio.ini file:

[env:swervolf\_nexys]  
platform = chipsalliance  
board = swervolf\_nexys  
framework = wd-riscv-sdk, freertos  
debug\_tool = whisper

Here’s my program:

```auto
#include "FreeRTOS.h"

#include "task.h"

#include <bsp_printf.h>

#include <bsp_mem_map.h>

#include <bsp_version.h>

void vTask1(void *pvParameters);

void vTask2(void *pvParameters);

int main(void)

{

    

    xTaskCreate(&vTask1, "Task 1", 1024, NULL, 1, NULL);

    xTaskCreate(&vTask2, "Task 2", 1024, NULL, 1, NULL);

    vTaskStartScheduler();

    return 0;

}

void vTask1(void *pvParameters)

{

    for (;;)

    {

        printfNexys("Task 1\r\n");

        vTaskDelay(pdMS_TO_TICKS(1000));

    }

    vTaskDelete(NULL);

}

void vTask2(void *pvParameters)

{

    for (;;)

    {

        printfNexys("Task 2\r\n");

        vTaskDelay(pdMS_TO_TICKS(1000));

    }

    vTaskDelete(NULL);

}

```

I’m getting the below error:  
task\_code.c:14: undefined reference to `xTaskCreate’

Please help me resolve this issue.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [August 28, 2021, 8:03am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/2 "2021-08-28T08:03:14Z")

</div>

_Undefined reference to xTaskCreate_ means you didn’t compile and link the related FreeRTOS source files (in this case tasks.c) to your program. You need to setup your build environment correctly.

---

<div class="post-metadata">

**Author:** ![vinceab](https://avatars.discourse-cdn.com/v4/letter/v/c5a1d2/32.png) [@vinceab](https://forums.freertos.org/u/vinceab)\
**Post date:** [August 28, 2021, 8:27am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/3 "2021-08-28T08:27:59Z")

</div>

To my knowledge the source files have been compiled. But where should they be located in PlatformIO to compile ?

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [August 28, 2021, 8:48am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/4 "2021-08-28T08:48:49Z")

</div>

Sorry - I’m not familiar with PlatformIO. But isn’t there a working demo you could check or use as starting point ?

---

<div class="post-metadata">

**Author:** ![vinceab](https://avatars.discourse-cdn.com/v4/letter/v/c5a1d2/32.png) [@vinceab](https://forums.freertos.org/u/vinceab)\
**Post date:** [August 28, 2021, 8:59am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/5 "2021-08-28T08:59:07Z")

</div>

Yes, there exists a working demo and that was running fine. However when I tried to compile my own code, I wasn’t able to.

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [August 28, 2021, 9:19am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/6 "2021-08-28T09:19:52Z")

</div>

The undefined reference error most likely comes from the linker, so you appear to have problems with your linker setup.

---

<div class="post-metadata">

**Author:** ![vinceab](https://avatars.discourse-cdn.com/v4/letter/v/c5a1d2/32.png) [@vinceab](https://forums.freertos.org/u/vinceab)\
**Post date:** [August 28, 2021, 9:36am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/7 "2021-08-28T09:36:05Z")

</div>

I don’t have much knowledge about the linker setup. Could you help me with that?

---

<div class="post-metadata">

**Author:** ![PaulB-AWS](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@PaulB-AWS](https://forums.freertos.org/u/PaulB-AWS)\
**Post date:** [August 30, 2021, 6:39pm UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/8 "2021-08-30T18:39:39Z")

</div>

@vinceab : I found a demo for the same board over on this [github](https://github.com/platformio/platform-chipsalliance/blob/master/examples/rtosal-freertos/platformio.ini).

Could you try replacing the following line in your platform.ini

```auto
[env:swervolf_nexys]

```

with

```auto
[env:rvfpga]

```

Thanks much,  
Paul

---

<div class="post-metadata">

**Author:** ![vinceab](https://avatars.discourse-cdn.com/v4/letter/v/c5a1d2/32.png) [@vinceab](https://forums.freertos.org/u/vinceab)\
**Post date:** [September 3, 2021, 6:37am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/9 "2021-09-03T06:37:17Z")

</div>

It’s still not compiling. The demo used in the GitHub repo. did not use the FreeRTOS header files. It created its own custom source files.

---

<div class="post-metadata">

**Author:** ![archigup](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/archigup/32/1418_2.png) [@archigup](https://forums.freertos.org/u/archigup)\
**Post date:** [September 14, 2021, 12:38am UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/10 "2021-09-14T00:38:51Z")

</div>

Do you have configSUPPORT\_DYNAMIC\_ALLOCATION set in your FreeRTOS config?

---

<div class="post-metadata">

**Author:** ![Torey](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@Torey](https://forums.freertos.org/u/Torey)\
**Post date:** [September 24, 2021, 3:30pm UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/11 "2021-09-24T15:30:44Z")

</div>

XTaskCreate()/xTaskGenericCreate() are base functions that are always included no matter what the configuration of the system so the only thing that comes to mind is that you are not building the source file that contains the function’s definition. Are you building FreeRTOS/Source/tasks.

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [September 24, 2021, 3:38pm UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/12 "2021-09-24T15:38:02Z")

</div>

This is not C++ code by any chance? If so you need to wrap your #includes into an extern “C” declaration.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [September 24, 2021, 4:09pm UTC](https://forums.freertos.org/t/undefined-reference-to-xtaskcreate/13342/13 "2021-09-24T16:09:31Z")

</div>

XTaskCreate needs configSUPPORT\_DYNAMIC\_ALLOCATION = 1 (which is the default) to be present.

You also needs tasks.c to be part of the project.
