Src/main.cpp versus cores/arduino/main.cpp

Could someone explain the relation between main.cpp existing in framework-arduinostm32/cores/arduino folder and the main.cpp file which we create in /src folder; should I use a different name for my source ?

Not necessary. Although the file names are the same, the way PlatformIO compiles the files, the resulting object files (both called main.cpp.o for both files) from these compilation units will end up being stored in different folders – namely \.pio\build\<env name>\FrameworkArduino\main.cpp.o and .pio\build\<env name>\src\main.cpp.o respectively. The compiler will not confuse these files since they are refered to by their relative paths in the linking command.

You should just take care to not create .h files which exist elsewhere – since .h files can be refernecd by just their name #include <header.h>, there’s a possibility for confusion if such a file exist in two folders which are both in the global include path.

1 Like