I am trying to use multiple source and header files, but building fails. Since I am targeting an ESP-IDF framework, I have included appropriate minimal source, header and configuration files.
My PlatformIO Core: 4.3.2a1, Home: 3.1.1, using VS Code.
It is my hope that someone can make the required changes to the configuration files, header and source files (#include statements or whatever else) to allow building in two scenarios:
Scenario 1. Multiple c/c++ files in the project src directory and header files the appropriate directory.
Scenario 2. Add c/c++ and header files in the project lib directory.
Here are the source and header files:
Main.c:
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include <AnotherFile.h>
//#include "..\lib\AnotherFile.h"
void app_main()
{
while(1)
{
printf("Hello World %d\n", iTake5()); // iTake5() in AnotherFile.cpp
vTaskDelay(500 / portTICK_RATE_MS);
}
}
AnotherFile.h:
#ifndef _ANOTHER_FILE_H_
#define _ANOTHER_FILE_H_
int iTake5(void);
#endif // _ANOTHER_FILE_H_
AnotherFile.cpp:
#include <AnotherFile.h>
//#include "AnotherFile.h"
int iTake5(void)
{
return 5;
}
platformio.ini (the first two lines seem unnecessary because they are the default locations, so they are commented out):
[platformio]
;include_dir = "Crap003\include"
;lib_dir = "Crap003\lib"
[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = espidf
build_type = debug
;build_type = release
monitor_speed = 115200
debug_tool = esp-prog
debug_init_break = tbreak setup
CMakeLists.txt:
set(app_sources
"Main.c"
"AnotherFile.cpp"
)
idf_component_register(SRCS ${app_sources})
Scenario 1. Expected that Main.c and AnotherFile.cpp would be in src, with AnotherFile.h in include (or src?). #include statements use <>, as seen in an example - if quotes are required, please set as required. Please list any changes made to any files!
Scenario 2. Expected that Main.c would go to src. AnotherFile.h and AnotherFile.cpp in lib. It would seem that AnotherFile.cpp wouldn’t be listed in CMakeLists.txt.
#include statements use <> - if quotes are required, please set as required. Please list any changes made to any files!
As a bonus, if it is desired to have multiple subdirectories within lib (e.g. Foo and Bar), could <> still be used for #include statements, with changes to platformio.ini (and what would those changes be)? If quotes are required, please indicate a correct #include in Main.c.
I would like to create a small set of simple examples with these results, in addition to a few RTOS concepts for those new to this environment, like me! Done by moderation
Many thanks in advance.
P.S. Sorry about the code formatting. How do I include a code sample so it formats properly?