Manual #include functionality in Web IDE?

It looks like the Web IDE doesn’t allow manual addition of #include libraries…

I successfully created a program in the Web IDE, then created a second program by cutting and pasting the code before modifying. Even before modifying, the compiler returned errors on each of the #include “foo.h” statements. Even though it was an exact cut & paste from a working program.

The workaround was to delete all #include statements and recreate via the library icon within the Web IDE, which seemed unnecessary.

Just wondering if this was by design?

John

Try leaving a line before your #include statements, sometimes it does not pick up #includes on line 1

Not sure if it’s by design or not, but the compiler doesn’t yet automatically pick up on included libraries. By selecting them from the libraries interface, the IDE knows which files to include.

When we talk about #include "foo.h" are you refering to a library from the library repository or one that you’ve provided yourself via the (+) add tab button?

If the former, then the reason is that with creating a new project you are actually getting a project folder on the build farm where your project resides. And if you want to use a library from the repository the system will copy the files of that library into your project folder. Hence when you only supply an #include "someRepoLib/someRepoLib.h" in a new project where you haven’t imported the library to, then there will be a no such file error.

But if you actually mean a private library, then the system will automatically add a #include "myPrivateLib.h" line to your project .INO file. If you then copy-paste some code that already contains such a include line and you haven’t ensured against double inclusion (e.g. #pragma once or #ifndef ... #def ... #endif) in your library, then you will get an error again.

So to be certain, what you actually are up against, we’d need to see some of your code, the errors you are seeing and maybe also a screenshot of your Web IDE showing the top of your .INO and the open code drawer < >.

And as @joe4465 suggested, the preprocessor might also muddle things up :wink:

Thanks for comments…you answered the question. Using the icon to create the #include statements completes tasks behind the scenes (copying library files into the local project folder) that make pasting code problematic.

Solution: Always use the library icon to use any repository libraries! You can verify proper usage by comparing the “Included Libraries” list in the white bar to the left of the code to the code’s include statements.

For any still interested, here the top several lines:

// This #include statement was automatically added by the Particle IDE.
#include "HttpClient/HttpClient.h"

// This #include statement was automatically added by the Particle IDE.
#include "OneWire/OneWire.h"

// This #include statement was automatically added by the Particle IDE.
#include "spark-dallas-temperature/spark-dallas-temperature.h"