PlatformIO Community

How to mix C++ and C code in PlatformIO for ESP32


I’ve been using platformIO for a project that will interface with vending machines.

I have written some code in C with ESP-idf framework also with FreeRTOS. They were purely written in C.

I want to continue using the C files I have already written and I also want to use freeRTOS.

Recently, I wanted to mix some Arduino code into my project (which are I assume C++ codes) because there many libraries that can be easily used such as Wi-Fi, Bluetooth, RFID etc.

How can I use the Arduino libraries with my C codes? I also want to create tasks with Arduino codes in FreeRTOS.

Is there any example where arduino, C++ and C codes are used in conjunction with each other as freeRTOS tasks?

Thank you!

I hope I was clear.

C/C++ interworking does not depend on PlatformIO or the ESP32 platform, it’s all about the pure C/C++ language constructs. Calling C++ code from C code is possible if the C++ code declares it as extern "C". In reverse, C++ code can call C code in the same way (extern "C" for the C-declared functions). Standard C++ has all the info you need.