maniacbug / StandardCplusplus

Standard C++ for Arduino (port of uClibc++)
594 stars 182 forks source link

Added an important instruction to README.md. #23

Closed allyourcode closed 1 year ago

allyourcode commented 7 years ago

Namely, that you need to #include . 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 commented 7 years ago

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

matthijskooijman commented 7 years ago

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.

allyourcode commented 7 years ago

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 , 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 at all, but I assume there is some technical limitation which prevents getting rid of this requirement?

matthijskooijman commented 7 years ago

Ideally, you wouldn't need to #include 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? :-)