Calling functions from an array of pointers in a library causes 'undefined reference to' error I am trying to create a library, where I have an array of pointers to functions in it. This array is used by other functions in the library. This is the code of the header file:

class Lib {
  public:
    static void call();
    static void (*caller[])();
  private:
};


This is the code of the .cpp-file:

#include "Lib.h"

void (*caller[2])();

void Lib::call() {
  caller[0]();
}


The sketch executing this is

#include &lt;Lib.h&gt;

void setup() {
  Lib::call();
}

void loop() {}


When I try to compile this, I get the following error:


  undefined reference to `Lib::caller'
  collect2: error: ld returned 1 exit status
  Mehrere Bibliotheken wurden für "Lib.h" gefunden


Another weird thing is that the error about the multiple found libraries goes away if I take away the line

Lib::call();


However, if I put the same code directly into the sketch like so:

void (*caller[2])();

void call() {
  caller[0]();
}

void setup() {
  call();
}

void loop() {}


I get no error. What's the problem here?
void (*caller[2])();


should be:

void (*Lib::caller[2])();


Since you are defining storage space for a static member variable you have to tell the compiler what class it's a static member of.