user1499: I want to try out this library:
https://github.com/connornishijima/arduino-volume3
I downloaded the zip file from github, renamed it, and included it as a library in the IDE.
So run one of the examples, A4_440HZ
This is its code:
#include "Volume3.h"
#define speakerPin 9

uint16_t frequency = 440;

void setup() {
  // Nothing neeeded here!
}

void loop() {  
  for(uint16_t volume = 0; volume < 1023; volume++){
    vol.tone(speakerPin,frequency,volume);
    delay(1);
  }
  for(uint16_t volume = 1023; volume > 0; volume--){
    vol.tone(speakerPin,frequency,volume);
    delay(1);
  }
}

And i get this error:
Error Compiling
A4_440Hz.cpp.o: In function `loop':
/usr/share/arduino/A4_440Hz.ino:12: undefined reference to `vol'
/usr/share/arduino/A4_440Hz.ino:12: undefined reference to `vol'
/usr/share/arduino/A4_440Hz.ino:16: undefined reference to `vol'
/usr/share/arduino/A4_440Hz.ino:16: undefined reference to `vol'
collect2: error: ld returned 1 exit status

I have no idea what is to blame, or how to mitigate it.
This is the first time that an included example from a library does not play out of the box.

user7508: 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?

1499: <p>I want to try out this library:
<a href="https://github.com/connornishijima/arduino-volume3" rel="nofollow noreferrer">https://github.com/connornishijima/arduino-volume3</a></p>
<p>I downloaded the zip file from github, renamed it, and included it as a library in the IDE.</p>
<p>So run one of the examples, <code>A4_440HZ</code>
This is its code:</p>
<pre><code>#include &quot;Volume3.h&quot;
#define speakerPin 9

uint16_t frequency = 440;

void setup() {
  // Nothing neeeded here!
}

void loop() {  
  for(uint16_t volume = 0; volume &lt; 1023; volume++){
    vol.tone(speakerPin,frequency,volume);
    delay(1);
  }
  for(uint16_t volume = 1023; volume &gt; 0; volume--){
    vol.tone(speakerPin,frequency,volume);
    delay(1);
  }
}
</code></pre>
<p>And i get this error:</p>
<pre><code>Error Compiling
A4_440Hz.cpp.o: In function `loop':
/usr/share/arduino/A4_440Hz.ino:12: undefined reference to `vol'
/usr/share/arduino/A4_440Hz.ino:12: undefined reference to `vol'
/usr/share/arduino/A4_440Hz.ino:16: undefined reference to `vol'
/usr/share/arduino/A4_440Hz.ino:16: undefined reference to `vol'
collect2: error: ld returned 1 exit status
</code></pre>
<p>I have no idea what is to blame, or how to mitigate it.</p>
<p>This is the first time that an included example from a library does not play out of the box.</p>
 7508: <p>This is kind of a weird situation. The library declares the object
<code>vol</code>, but fails to define it. On the ancient version of the Arduino IDE
you are using, compilation fails, understandably, because <code>vol</code> has
never been defined. What is weird is that, on a more recent version
(1.8.15 on Ubuntu here), compilation succeeds.</p>
<p>It is worth noting that <code>vol</code> belongs to the class <code>Volume</code>, which is an
empty class. As such, it only plays the role of a namespace for the
functions <code>vol.tone()</code> and <code>vol.noTone()</code>. Strictly speaking, as <code>vol</code>
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.</p>
<p>Anyhow, you have two options:</p>
<ul>
<li><p>upgrade your installation of the Arduino IDE</p>
</li>
<li><p>declare <code>Volume vol;</code> near the top of the sketch.</p>
</li>
</ul>
<p><strong>Edit</strong>: I did some tests and it appears that, as I suspected, this is
related to <a href="https://en.wikipedia.org/wiki/Interprocedural_optimization" rel="nofollow noreferrer">link-time optimization</a> (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.</p>
<p>The library could be fixed by defining <code>vol</code> in Volume3.cpp, although
this would create a weird empty object in the BSS. Another option would
be to declare both methods as <code>static</code> within Volume3.h. This would make
the compiler know it doesn't actually need to reference the <code>vol</code> object
when one of its methods is called.</p>
<p>Would you submit a pull request with one of those fixes?</p>
