Including header files and compile using particle CLI

For whatever reason, I got in the habit of running particle flash/compile by referencing the actual .ino file. Example: particle flash myphoton src/main.ino. This worked great and life went on.

Then, I needed to include extra files for a bit more complex coding. I needed to include my own header file. I put #include ‘myextrafile.h’ in my main file. It never worked. I tried everything, read tons of forum posts and just ran trials and errors. I kept getting an error in the compilation that myextrafile.h couldn’t be found.

It was only after re-reading the particle compile tutorial that I noticed it said you can either point directly to the file OR at the directory itself (or nothing to use current directory). Once I tried this, the linking of the header file worked just fine!

My point in sharing all this, is perhaps some one else out there may come across the same stumbling block and can get past it quickly.

But, also, as a suggestion to the Particle team to update your documentation. Add a few sentences or paragraph laying out the process to include files and compile from the CLI. And that you must NOT reference the .ino file directly, but must reference the directory.

If you can spare the time, the docs are open source on github, and pull requests to improve them are more than welcome. That has a higher chance of being adopted sooner, than waiting for it to be picked up by Particle directly.

Regardless, thanks for sharing!

Good to know. Thanks Moors7. I’ll jump in there. If you have a suggestion of what page to modify I’ll heed your advice, otherwise, I’ll poke around.

I’d say you’d be a better judge of that than I am, since you haven’t been able to find it. As such, you ought to have a clue where you looked for it. That’d be a goo place I guess :wink:
I’d think somewhere around here would make sense: https://docs.particle.io/reference/developer-tools/cli/#particle-compile

You can click the “edit” button in the top right corner of the docs to take you to the correct github location.

The recommended way would be to use particle project create to have a fully setup project that also contains a project.properties file which is the file you should provide to the build command (or the directory that contains that file).

1 Like