如何使用预处理器判断是否使用 ESP-IDF 框架 (PlatformIO)
你可以使用 如何在 PlatformIO 中打印所有预处理器标志 打印预处理器标志。你可以使用以下命令找到所有 ESP-IDF 相关标志
print_pio_flags.sh
cat .pio/build/esp32dev/src/main.o | grep IDF对于空的 main.c 文件,结果只是
idf_version_define.txt
#define IDF_VER "5.1.2"注意,IDF_VER 对 Arduino 也会定义,因为 Arduino 在内部使用它。
所以你可以使用以下检查来区分 Arduino 和 ESP-IDF
esp_idf_check.cpp
#if !defined(ARDUINO) && defined(IDF_VER)
// ESP-IDF code goes here
#else
// Non-ESP-IDF code goes here
#elseCheck out similar posts by category:
ESP8266/ESP32
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow