Arduino not finding / including my libraries in the MultiWii.cpp file

Hi,

I want to modify the MultiWii flight controller code a little bit for my needs. I have an ultrasonic sensor that I want to use. Therefore I try to iclude the NewPing library at the top of the MultiWii.cpp file, but it always gives me “NewPing.h: No such file or directory”. The same occurs when I try to include other libs (e.g. LCDBitmap).

However, I installed the lib properly in the libraries folder and it shows up in the GUI under Sketch > Include Library. Furthermore I am able to include the libraries in any other sketch without errors. I have tested the NewPing lib already successfully. Only the MultiWii sketch throws errors.

Is there something that I have to consider when including libs in a cpp file?

Any ideas?

Well, I found a workaround: Add the include statement in the cpp file as well as in the main ino file. Arduino will be able to find the library then.

However, there is no other include in the ino file, so my new question is: how to properly include a library in a cpp file? Why does the MultiWii code not require additional #include statements in the ino file?

Original workaround: http://forum.arduino.cc/index.php?topic=64365.0

However, there is no other include in the ino file, so my new question is: how to properly include a library in a cpp file?

You seem to have figured that out.

What you seem to be asking now is how to include a header file in the library without including it in the sketch. The answer to that is that you can't do that.

Why you can't should be fairly obvious. Using one library should not include other libraries that include other libraries that include other libraries, without it being clear, at the sketch level, that such a thing is happening.