StandardCplusplus icon indicating copy to clipboard operation
StandardCplusplus copied to clipboard

Added an important instruction to README.md.

Open allyourcode opened this issue 8 years ago • 4 comments

Namely, that you need to #include <StandardCplusplus.h> . For searchability, I mention the error message that will appear if you fail to do this.

New instruction(s) are in a new section named "How do I use it?"

allyourcode avatar Dec 26 '16 02:12 allyourcode

I'm assuming that the #include needs to be in every file that has STL #incldues...

allyourcode avatar Dec 26 '16 02:12 allyourcode

Nope, it just needs to be in a single .ino file (or .c/.cpp file in a library that uses it). Doing so causes it to be put in the include path for all compilation runs.

matthijskooijman avatar Dec 26 '16 09:12 matthijskooijman

I've added elaboration to my change.

I've done a bunch of experiments, and as best as I can tell, the rule is "you need (at least) one #include <StandardCplusplus.h>, and it has to appear before all your C++ standard library includes". But not #include'ing it yourself directly (when you use C++ std lib yourself) seems fragile. E.g. this does not build, but it does if you swap the two #include "a.h" vs. #include "b.h" lines in includez.ino

Ideally, you wouldn't need to #include <StandardCplusplus.h> at all, but I assume there is some technical limitation which prevents getting rid of this requirement?

allyourcode avatar Dec 29 '16 00:12 allyourcode

Ideally, you wouldn't need to #include <StandardCplusplus.h> at all, but I assume there is some technical limitation which prevents getting rid of this requirement?

To decide what libraries a sketch needs, it builds a list of .h files that each library has. Then it runs the preprocessor on the sketch, to find out what files it tries to include but are not available. Every missing include is then matched against that list, to select a library for each one.

The problem here is that this library uses include files without the .h extension, which will not show up in the list and thus not allow the Arduino IDE to mark this library as required.

Does that clarify things? :-)

matthijskooijman avatar Dec 29 '16 20:12 matthijskooijman