PlatformIO Community

ESP32 lib dependency works on Arduino but not ESP-IDF

I’m struggling to get code that uses an external GitHub library to compile using ESP-IDF but which works fine if I select the Arduino framework

Here is my platform.ini

platform = espressif32
board = esp32doit-devkit-v1
framework = espidf
monitor_speed = 115200
lib_deps =

This is the main.c

#include "esp32_can.h"

void app_main() {

and this is the error I see when compiling

Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 32 1.12.4 > DOIT ESP32 DEVKIT V1
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
 - framework-espidf 3.40001.200521 (4.0.1) 
 - tool-cmake 3.16.4 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - tool-ninja 1.9.0 
 - toolchain-esp32ulp 1.22851.190618 (2.28.51) 
 - toolchain-xtensa32 2.80200.200226 (8.2.0)
Reading CMake configuration...
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/esp32doit-devkit-v1/esp-idf/src/main.c.o
Generating LD script .pio/build/esp32doit-devkit-v1/esp32_out.ld
Generating partitions .pio/build/esp32doit-devkit-v1/partitions.bin
src/main.c:1:10: fatal error: esp32_can.h: No such file or directory

* Looking for esp32_can.h dependency? Check our library registry!
* CLI  > platformio lib search "header:esp32_can.h"
* Web  >

 #include "esp32_can.h"
compilation terminated.
*** [.pio/build/esp32doit-devkit-v1/esp-idf/src/main.c.o] Error 1
Compiling .pio/build/esp32doit-devkit-v1/esp-idf/app_trace/app_trace.c.o
============================================================ [FAILED] Took 8.62 seconds ============================================================
The terminal process "platformio 'run'" terminated with exit code: 1.

I read that I need to include the header file in the include directory, but I never needed to do this with the arduino framework which compiles just fine.

Does anyone know why it would work with arduino but no esp-idf?

I should have added that the files look to be available but not on the include path

$ find . -name esp32_can.h

Well the library only has a which is an Arduino format. Thus it’s implied that it only works for Arduino.

If it had a library.json in PlatformIO format delcaring its frameworks as both Arduino and ESP-IDF, it at least be recognized as a compatible library. Otherwise PlatformIO will supress non-compatible libraries.

If you are absolutely sure this library is also supposed to work for pure ESP-IDF (which I also personally doubt), you can set the lib_compat_mode as the docs say. in the platformio.ini

lib_compat_mode = off

What you identified makes sense now. Many thanks for your advice.

I may ask the author to see if it is possible for his library to support both Arduino and ESP-IDF