Project folder / file convention

I was looking at github and seen a few repos and noticed a convention that was a little confusing to me.

I noticed that most projects had a firmware folder. (“that made sense”) but where I got confused was the difference between what looks to be the main app meant to be compiled and an following example folder which looks to be competing with the main app.cpp file.

This is what I seen as convention.

  • firmware ¬
    • examples ¬
      • SomeExample.ino
    • SomeMainApp.cpp
    • SomeHeader.h

Whats confusing is why would I need an example if I have the SomeMainApp.cpp?
From what I can tell Both the SomeMainApp.ccp and the SomeExample.ino both #include SomeHeader.h but very greatly from each other in most cases.

The example looks to be more focused arround the spark/photon with a setup/loop method where I dont see that at all in the SomeMainApp.ccp. At the same time the example only looks to be using the header file.

Not really sure what to make of this convention.

I guess most the repos you looked at were library repos, where the main thing is the library and not the examples that just show how to use the library.

The example folder shows you how to use the library. The code under /firmware is the library.


So for the example in the case of the TinyGPS it looks like its only including the header file. How is it using the cpp file?

Thank you for the example.

Header files are there to tell the compiler that there will be some implementation for the mentioned functions and stuff.
So when it compiles your code, which uses some of the external functions, the compiler will be happy, because he got told of their existance.
It will also compile the .CPP files he finds in the library folders.

When the compiler is done, the linker brings all the seperate parts togther (links them) and if all external references that the compiler willingly accepted can be matched to an implementation, the linker will be happy to. If not - not :wink:

That’s a very basic description how C programs are written and built - if you want more detail, there are loads of other resources on the web.

1 Like