Is there any way to just compile one file by itself? This is something I do regularly when I am developing with gcc-based projects. I rarely use either 1.x or 2.x IDE, just using Arduino-CLI (there doesn't seem to be a forum category for this under the development tools section).
When I tried to just add single file to the CLI command, it errors out because it thinks the name I gave is an INO project file.
Because many Arduino sketches only contain a single .ino file, it's easy to think of that file as the sketch. However, it is the folder that is the sketch. The reason is that sketches may consist of multiple code files and the folder is what groups those files into a single program.
So just store each of your sketches in a separate folder, and pass Arduino CLI the path to that folder.
Well, these are all files belonging to one sketch. I have half a dozen or so separate pairs of files, like filter.cpp and filter.h, along with one main sketch file, say project.ino. This all works just fine.
When I'm making some big changes, and I know the whole project won't compile, it is helpful to just run a single file through the compiler and fix errors only in that file. For example, in the gcc world, gcc -c filter.cpp. I guess there is no equivalent command in Arduino-CLI world?
It's actually a lot easier than I described. Create a new sketch (directory and ino file), copy the file that you want compile (and the needed includes) to the new sketch directory and compile the new sketch.