1

I am using Jeff Rowberg's MPU6050 library, and I simply don't understand what is going on in the following lines of the first example (MPU6050_raw.ino):

#include "I2Cdev.h"
#include "MPU6050.h"

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE
// implementation is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include <Wire.h>
#endif

So, what I got from that is, if I2Cdev is using Wire instead of some alternative I2C library, I should include Wire.h. I really don't see why that's necessary, so I removed the line in which Wire.h is included, and got this error:

C:\Users\Franco2500k\Documents\Arduino\libraries\I2Cdev/I2Cdev.h:80:26: fatal error: Wire.h: No such file or directory
     #include <Wire.h>

So, apparently, I2Cdev.h already tries to include Wire.h, but somehow fails? And another #include a few lines later goes back in time and fixes everything? Can someone explain what is going on?

1

The Arduino IDE means well, really it does. It copies your source, the device core, and any libraries used by your source all to a separate directory so that it doesn't poison any of their original locations unintentionally.

But of course, there's something missing from that list. The IDE doesn't copy libraries used by other libraries. Therefore if you don't include Wire.h in your .ino file then Wire will be missing from the build and you get the error observed. Cracktastic.

  • Indeed. I describe this process here: arduino.stackexchange.com/questions/13178/… – Nick Gammon Jul 29 '15 at 6:22
  • Weird. So, if I understood that right, I2Cdev.cpp is not compiled, waiting to be linked; it is instead compiled with the entire project every time I build it, and the IDE knows which sources to compile by scanning the my source for #includes. Is that right? – DoubtBearer Jul 29 '15 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.