Compiling a complex project

Hi
I have a quite large project with several files organized in several folders and subfolders.
I place them in the src folder of my main folder so that the main folder only has the following:

  • mycode.ino
  • src
  • partitions.csv (the code is for ESP32)

If I compile this complex code on Linux for example, I can tell the compiler and the linker to search for all the files using -I argument.
I expected that this would be taken care of automatically by using this src folder. However, it is not the case because I need to provide detailed paths for the #include of header files.

I hoped that I could add some similar option in the platform.txt file to help the compiler and linker find all the files they need without changing the paths in the #include instructions.

Is this possible, or do I really need to provide the detailed paths of all .h files ?

assuming you have .h files in the SRC directory in the root .ino file you need to reference them so

#include "src/Water_level_sensor/Water_level_sensor.h"
#include "src/relays/relays.h"
#include "src/RTC/RTC.h"
#include "src/controlLoop/contolLoop.h"
//#include "src/BLE/BLE.h"
#include "src/NVMstorage/NVMstorage.h"
#include "src/Keyboard_tests/Keyboard_tests.h"

Thanks for your answer.
So basically, I need to provide in the #include statements the path to the header file relative to the file where the #include is.
For example, a file src/folder1/folder2/something.cpp that would need a header file in a folder such as src/include/myfunc/myfunc.h would require:

#include ../../include/myfunc/myfunc.h

There is no easier way to declare the includes?

in a large C++ programs I organize .cpp and ,h files into subdirectories
the Arduino IDE is a more restrictive using the subdirectory src, e.g.

test - test.ino
     - src - relay - relay.h 
                   - relay.cpp
           - control - control.cpp
                     - control.h

Hi @lesept.

Not at this time. The Arduino developers are tracking the request to support bundling libraries with sketches here:

With the requested feature, Arduino development tools would do library discovery in the libraries subfolder of the sketch, just the same as it does in the existing libraries folders. This means that you could use #include directives for the sketch bundled libraries exactly the same as you do for non-bundled libraries.

Apart from putting all the includes at the top level, there seems to be no alternative.

I only use Arduino IDE for the simplest of projects.

if you organize the .cpp and .h files into subdirectories you generally have to use #include to the specific subdirectory, e.g. using the Microchip MPLABX IDE, in main.c

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include<stdarg.h>
#include <time.h>
#include "hardware.h"
#include "timer/timer.h"
#include "RTC/RTC.h"
#include "relays/relays.h"
#include "adc/adc.h"
#include "I2C/i2c.h"
#include "CayenneLpp/CayenneLpp.h"
#include "Bluetooth_BM71/Bluetooth_bm71.h" 
#include "ControlLoop/controlLoop.h"
#include "EZO_sensors/Ezo_i2c.h"
#include "keyboard_tests/keyboard_tests.h"
#include "Quectel_EG21_modem/Quectel_EG21_modem.h"
#include "Quectel_EG21_modem/Quectel_EG21_GPS.h"
#include "Quectel_EG21_modem/Quectel_EC21_MQTT_SLL.h"  
#include "MB85RC64_FRAM/MB85RC64_FRAM.h"
#include "MC3416_accelerometer\MC3416_accelerometer.h"

subdirectories in the root directory with main.c and other .c and .h files