Skip to main content
2 of 2
+ cause is LTO.
Edgar Bonet
  • 45.2k
  • 4
  • 42
  • 81

This is kind of a weird situation. The library declares the object vol, but fails to define it. On the ancient version of the Arduino IDE you are using, compilation fails, understandably, because vol has never been defined. What is weird is that, on a more recent version (1.8.15 on Ubuntu here), compilation succeeds.

It is worth noting that vol belongs to the class Volume, which is an empty class. As such, it only plays the role of a namespace for the functions vol.tone() and vol.noTone(). Strictly speaking, as vol has no data (its size is zero), the compiler should never need to access it. My guess is that the newer Arduino manages to compile this only because it uses different optimization settings than the ancient 1.0.5.

Anyhow, you have two options:

  • upgrade your installation of the Arduino IDE

  • declare Volume vol; near the top of the sketch.

Edit: I did some tests and it appears that, as I suspected, this is related to link-time optimization (LTO). Since version 1.5.7, the Arduino IDE enables LTO, and when this is the case, the linker doesn't complain about missing empty objects.

The library could be fixed by defining vol in Volume3.cpp, although this would create a weird empty object in the BSS. Another option would be to declare both methods as static within Volume3.h. This would make the compiler know it doesn't actually need to reference the vol object when one of its methods is called.

Would you submit a pull request with one of those fixes?

Edgar Bonet
  • 45.2k
  • 4
  • 42
  • 81