Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


FreeRTOS, C++ and xTaskCreate() function

Posted by lagavulin21 on November 3, 2013


I try to create a C++ application (and C++ tasks) based on FreeRTOS but I can not call the xTaskCreate() function from my C++ code.

Default FreeRTOS main() function:

/* default FreeRTOS main() */

int main( void )
    /* Exported C++ function */

Below the header and source files based on the following both examples:

http://sourceforge.net/p/freertos/discussion/382005/thread/5d5201c0 http://interactive.freertos.org/entries/223648-using-freertos-with-c

I think I have included all relevant C-header files in my C++ header:

#ifdef __cplusplus
extern "C" {
#include <FreeRTOS.h>
#include <task.h>
#ifdef __cplusplus    

... and my C/C++ wrapper functions:

#ifdef __cplusplus
extern "C" {
void tskWrp(void* p);
void runTask();
#ifdef __cplusplus

C++ source file: prl_task.cc

/* C++ source file: prl_task.cc /*   

/* 2 simple tasks */

void vTask1( void ) {

void vTask2( void ) {

/* base class CTask */

CTask::CTask(char const* name,
	unsigned portBASE_TYPE priority,
	unsigned portSHORT stackDepth=1000) {

    /* Code works up to here! */    
    xTaskCreate(&tskWrp, (signed char*)name, 1000, this, 1, NULL);

void CTask::Task() {

/* derived class CTask1 */

CTask1::CTask1(char const* name,
            unsigned portBASE_TYPE priority,
	unsigned portSHORT stackDepth=1000) : CTask(name, priority,stackDepth) {

void CTask1::Task() {


/* interface functions C C++ */

void runTask(){

    CTask1 task("tsk",1,1000);

/* wrapper function */

void tskWrp(void* p) {


I can compile the code without errors but the xTaskCreate() function will be "ignored" and the program is not running on my MPU. If I call directly another functions e.g. vTask1() instead of xTaskCreate() the program works fine on the MPU.

By the way my IDE throws a warning "Function 'xTaskGenericCreate' could not be resolved". I'm not sure whether the IDE warning or any other reason is the cause of my problem.

Maybe someone can help me?


FreeRTOS, C++ and xTaskCreate() function

Posted by richard_damon on November 3, 2013

First, you shouldn't need the #ifdef __cplusplus lines to add the extern "C" stuff, as that should be in the headers already.

The other thing to note it that the FreeRTOS files MUST be compelled a C files, not C++ files, or they won't work right, The extern "C" stuff in the headers sets up the linkage properly for the cross language link. That might explain the could not be resolved problem.

FreeRTOS, C++ and xTaskCreate() function

Posted by lagavulin21 on November 3, 2013

If I will create a C-compiled freeRTOS.o object file and a C++ compiled application.o object file, is it possible to link both together by using g++?

The following link recommends to use g++ for the linking process in case ob mixing C and C++:


FreeRTOS, C++ and xTaskCreate() function

Posted by richard_damon on November 3, 2013

Yes, you should be able to link files compiled as C and files compiled as C++, that is the main purpose of the extern "C" syntax. As the link suggests, main should be C++, the libraries used should be C++, so the linker should generally be the C++ linker. The C compiler needs to be ABI complient with the C++ compiler.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists