عندما تستخدم PlatformIO لترجمة الـ firmware الخاص بك، يمكن بسهولة استخدام main.cpp بـ C++ بدلًا من main.c النقي بـ C بمجرد إعادة التسمية main.c إلى main.cpp
ومع ذلك، تحتاج أيضًا للتصريح عن app_main() بشكل صحيح. بعد قسم #include في main.cpp الخاص بك (أو في أعلى الملف إذا لم يكن لديك قسم #include بعد)، أضف هذا الكود:
app_main_declare.cpp
extern "C" {
void app_main(void);
}سيخبر هذا المترجم أن app_main() دالة C وليست دالة C++.
مثال main.cpp كامل
espidf_main_cpp_example.cpp
#include <cstdio>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
extern "C" {
void app_main(void);
}
void app_main() {
while(true) {
printf("Hello PlatformIO!\n");
// Wait for one second
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Check out similar posts by category:
C/C++ ESP8266/ESP32 PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow