Undefined reference to static variables

Hello.

I am trying to write my first library. I wanted to include an ISR function on it, and following what I read in this thread(http://forum.arduino.cc/index.php/topic,119462.0.html, reply #2) I made an ISR like the following :

ISR(TIMER2_OVF_vect, ISR_NOBLOCK){

	MultiTXRX::handleInterrupt();
}

MultiTXRX is the main class and has lots of public variables, handleInterrupt is a static function of that class. The handleInterrupt function modifies lots of these public static variables.

What happens is that when I try to compile my library the following errors appear :

C:\Program Files (x86)\Arduino\libraries\MultiTXRX/MultiTXRX.cpp:69: undefined reference to MultiTXRX::txBits' C:\Program Files (x86)\Arduino\libraries\MultiTXRX/MultiTXRX.cpp:69: undefined reference to MultiTXRX::txBits’
C:\Program Files (x86)\Arduino\libraries\MultiTXRX/MultiTXRX.cpp:71: undefined reference to `MultiTXRX::txTimer’

and so on, for every occurrence of one of these static variables (txBits, txTimer,…) in the handleInterrupt function.

What is the cause of this problem? How can I solve it?
Thank you :slight_smile:

Post you library as either an attachment or here on the post.

The library directory for the Arduino IDE is not the right place to put 3rd party libraries, but this probably isn't causing your problem. It looks as if your class implementation is wrong, probably either the member variables you're trying to access are not declared as static, or the static declaration is not visible to the compilation unit containing the static method implementation. However, this is only a guess since you haven't posted the code that contains the error.

With all your static variables ensure that they are declared inside the class, but defined out side.

struct Foo{
 
  static int MyStatic;
};

int Foo::MyStatic = 0;

//or simply
//int Foo::MyStatic;