Compile Error in Web IDE When Including More than One Library

Ok. I was trying to hack the tinker code to send some BMP085 (Adafruit) data to my cell phone. I immediately ran into trouble, and, after some hair pulling, I realized the Web IDE seemed to be upset that I included two libraries. So I did the following experiment:

  1. Save a copy of Tinker in the web IDE (copy and paste from Github into a new file).
  2. Complile it - all’s good.
  3. Fork a copy of Adafruit’s BMP085Test.
  4. Compile it - all’s good.
  5. Now, merely include application.h (#include “application.h”)
  6. Compile it - tons of errors

Merely including the second library seems to make the compiler have no idea what was in the Adafruit library.

From my experience with Arduino, I’m used to including as many libraries as I want- even if I don’t use all of them- and still having my code compile.

Can anyone explain what is going on here? Thanks.

Hi @wstreyer

Are your using the Adafruit BMP085 library that has been ported to Spark? There are often minor changes needed to port libraries like this and it looks like @krvarma has ported it for you.

Some Arduino libraries work without any porting but that is a bit rare–most require minor tweaks and a very small number require major surgery to work with Spark, especially if they use ATMEL specific code.

Everything I’ve done has been in the Web IDE. I pulled the Adafruit library from the library tab in the Web IDE. So, like I said, the code compiles, and it works when flashed. I can see the data in putty- no problem.

It’s when I try to add the Tinker code that it fails. After some frustration, I decided to drop in the tinker code one block at a time starting with #include “application.h”. This was all it took to cause trouble.

On second thought, I looked at the Adafruit library on Github, and found that application.h is already included in the their library. If I simply leave out my #include “application.h”, the code compiles.

It seems to be that duplicate library inclusions should simply be ignored. Otherwise, I would have to personally validate that I have not inadvertently included duplicate libraries that were already included in some other library.

I think it is probably the Spark preprocessor that is messing you up. You can turn it off if you need to. It is the thing that lets you avoid writing strict C/C++ with function prototypes and all forward references defined. You can write looser code using the preprocessor, so it is good for beginners etc. Arduino has a preprocessor too, but uses a much less strict compiler than gcc on Spark.

Application.h does indeed have the magic so it is included only once. That’s why I think the preprocessor is the likely problem.