I am facing that same problem, and have discovered that there are magic incantations which the IDE does or does not apply to files. In an attempt to simplify the construction of tiny sketches by beginners, it does unknown transformations of you code under unknowable conditions, which can result in spurious errors in what appear to be valid programs. I just split my large source into six files (it will probably be closer to 20 before I'm done) and it no longer compiles. I have to do "black box" experiments to figure out how to either evade the damage caused by these transformations, or compensate for the unknown transformations which are not being done.
While I have no argument against making things easier for beginners, it is also essential to support people like me, who have had 50+ years experience as programmers (and in my case, 20+ years with C++).
The simple, obvious, and (for any other environment) correct mechanisms fail in the Arduino IDE.