This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Is it possible to use C++ with TI-RTOS?

Is it possible to use C++ with TI-RTOS? If so, what Code Composer Studio project configuration settings should I enable/disable so that I can write code in C++.

As as test, I attempted to compile the TI-RTOS example project named: gpiointerrupt_StellarisLM3S9D96, which is an example provided by TI. I compiled it with Embedded C++ language option and also changed all the .c files to .cpp extension.

I get the following error: 

unresolved symbol GPIO_config, first referenced in C:\ti\tirtos_1_01_00_25\packages\ti\drivers\lib\instrumented\gpio_stellarisware.aem3<GPIO.oem3> gpiointerrupt_StellarisLM3S9D96 C/C++ Problem

  • You can use C++ with TI-RTOS. Did you change the "board.c" file to "board.cpp"? It defines globals that are used by driver libraries. C++ is name-mangling GPIO_config, but the C driver library is looking for GPIO_config. Use "extern "C" { };" around the GPIO_config variable.

    Todd

  • I have a "Board.h" file but not a "Board.c" file. For this specific example, I'm guessing you are talking about the "DK_LM3S9D96.c" file, which I changed to .cpp extension and I added the "extern C" block around the GPIO_config variable as you advised but with no success. I get the same error.

  • Yes, TI-RTOS generically says "Board.c" instead of the specific board name (e.g. DK_LM3S9D96.c).

    I'd leave the "Board.c" as a .c file and add the "extern C" to the gpioButtonFxn function in gpiointerrupt.cpp. That worked for me.

    Todd

  • Yes that solution worked when I removed the "Embedded C++" C/C++ Dialect in language options.

    So I take it that TI-RTOS won't run with that option turned on as it forces you to have all files as .cpp instead of both .c and .cpp, am I right? Are there any advantages/disadvantages of using/not using the Embedded C++ option on CCS?

     Edit: So, does that meanI have to put the extern "C" block around every task function?

  • TI-RTOS is no different than any other 3rd party library that is built with C. The examples and the board.c files are provided as reference code that is designed to be changed by a user. The header files for TI-RTOS drivers (and SYS/BIOS) have the "extern C" in them to allow them to work with C++ applications. TI-RTOS drivers do require the application provide a config structure.

    I played with this a little. I made the board.c a cpp file and added the extern "C" around the GPIO_config stuff. I got the unresolved GPIO_config. I removed the const from line

    const const GPIO_Callbacks TMDXDOCKH52C1_gpioPortBCallbacks = {
        GPIO_PORTB_BASE, INT_GPIOB,
        {NULL, NULL, NULL, NULL, gpioButtonFxn, NULL, NULL, NULL}
    };

    It built and ran properly. Note: I added extern "C" around the button code also. In ti\drivers\GPIO.c, the GPIO_config is not extern'd as a const...that might be a bug...probably a question for the codegen forum.

    Todd