OneButton - no compiling

the use of the OneButton library seems to be quite useful in my project, so I started to take a nearer look to the library.But even the simple examples, provided with the library, don't compile, e.g.:

//from Mathias Hertel's Github-page (
#include "OneButton.h"

// Setup a new OneButton on pin A1.  
OneButton button(A1, true);

// setup code here, to run once:
void setup() {
  // enable the standard led on pin 13.
  pinMode(13, OUTPUT);      // sets the digital pin as output
  // link the doubleclick function to be called on a doubleclick event.   
} // setup

// main code here, to run repeatedly: 
void loop() {
  // keep watching the push button:

  // You can implement other code in here or just wait a while 
} // loop

// this function will be called when the button was pressed 2 times in a short timeframe.
void doubleclick() {
  static int m = LOW;
  // reverse the LED 
  m = !m;
  digitalWrite(13, m);
} // doubleclick

// End

I get the following errors:

sketch_nov08b.cpp.o: In function `_GLOBAL__sub_I_button':
/usr/share/arduino/sketch_nov08b.ino:4: undefined reference to `OneButton::attachDoubleClick(void (*)())'
/usr/share/arduino/sketch_nov08b.ino:4: undefined reference to `OneButton::tick()'
/usr/share/arduino/sketch_nov08b.ino:4: undefined reference to `OneButton::OneButton(int, int, bool)'
collect2: error: ld returned 1 exit status

What is wrong with the code? I flashed it to an Arduino Uno. As long as this simple example doesn't run I feel no need using OneButton in my project.

Thanks for helping


I am sure that it will be of no consolation to you but the code compiles OK for me.

Where did you get the OneButton library from ?

Github: GitHub - mathertel/OneButton: An Arduino library for using a single button for multiple purpose input.

It looks like the OneButton.h was found correctly but the OneButton.cpp was not found in the same place. They should both be in libraries/OneButton/src in your sketch folder.

Did you open the example with File->Examples->OneButton->SimpleOneButton

Yes, both files are at their place:

richard@nuc:~/sketchbook/libraries/OneButton/src$ ls -l
total 12
-rw-rw-r-- 1 richard richard 6285 Nov 8 14:01 OneButton.cpp
-rw-rw-r-- 1 richard richard 3793 Nov 8 14:01 OneButton.h

But nevertheless when opening, as you suggested, with File->Examples->OneButton->SimpleOneButton:

SimpleOneButton.ino:19:23: fatal error: OneButton.h: Datei oder Verzeichnis nicht gefunden [file/directory not found]
compilation terminated.

The Mattias Hertel OneButton library is available in the IDE Library Manager. Which version do you have ? I have 1.3.0 installed

I have 1.3.0 installed

Fwiw, I have that version also, and OP's code compiled on an Uno with IDE 185.

In the library manager of IDE 2.1.0 unfortunately there is no "OneButton", so I have to download a zip file. Besides the library "" there are also "" down to, the last named you'll find on OneButton - Arduino Libraries, but also linking to M. Hartel's GitHub page.

So I downloaded the 1.3.0 version to my /temp-directory. Calling "Import library" in the IDE gave the following error: "The Library names must contain only alphabetical characters and numbers". So I renamed the file to "". Same error. Within the zip file there is a directory named "OneButton-1.3.0", which then became renamed to "OneButton130". Now the import ->seemed<- to work. In my "Add library" menu there is now an item "OneButton130".

But the compiler still doesn't like it. Renaming the library to be imported from "" to "" didn't help. I'm quite frustrated :frowning:

The files "OneButton.h" and "OneButton.cpp" are stored in ~/sketchbook/libraries/OneButton/src/
I'm thinking of using old fashioned code for reading the pushbuttons instead of using the OneButton library.



In the library manager of IDE 2.1.0

The latest IDE is 1.8.10.

What is 2.1.0?

Oh, my eyes...
In Help->over it reads (very, very small): 2:1.0.5+dfsg2-4, so at first glance I read 2.1.0. Sorry for that. I'll update.

Now everything is fine, I've updated to 1.8.10
Thanks to all,