Why is PlatformIO compiling h files not used anywhare?

I have a small ESP-01 based project (using the Arduino framework) which I try to package into a single cpp file to reduce the number of source files.
So at first I used a utils.h file in the include dir, but I have copied the few functions I need from it into main.cpp and commented out the references to utils.h everywhere.
But still when I build the project it tries to use that file anyway and the build breaks with an error:
multiple definition of SendWebRequest(String)'`
Why does this happen?
I have searched for all references like #include “utils.h” but they are all commented out and still it seems like the compiler tries to use the utils.h file even though it is not mentioned in any file used by main.cpp. How does it even find the utils.h file in the chain of files to compile?
And what can I do to make my project build???

Post your project or a minimal reproducable project that has that error and we’ll be able to tell you.

Also, should the linker error not tell you in which other file the function was defined, for a “multiple definitions of” error? What’s the full error message?

I have “solved” the problem by renaming the utils.h and utils.cpp files in include and src dirs respectively by adding .bak to their names.
These files are containing various utilities I have collected and are meant to be used in many different projects where I assumed only the used parts of them would be actually read and compiled but it seems like that assumption is wrong…

In the current case I only used two functions so I coped them into the main.cpp file and commented out the #includes, thinking that then the compiler would not touch them. But apparently that is not what happens. :frowning:

I was wondering how PlatformIO handles source files in general, since I am used to dev tools for Pascal (FreePascal) where only files explicitly named in the project files in uses clauses gets read by the build engine and compiled.
In this case though it seems like every file with the extension cpp in src and h in include gets read and compiled during a build. Is that really the case?

In such a case one cannot have multiple projects share subsets of the source files in the same dirs…