Undefined Reference to <namespace>::<variable>
<p>I'm working on some code to flag when changes have been made to a website. I've run into a problem using a static variable in the class, so I want to declare a variable in the namespace and set this ==1 when a change is made.</p>

<p>Here is some simplified code that I've written to represent the problem:</p>

<p>p.h:</p>

<pre><code>#include&lt;iostream&gt;
using namespace std;

#ifndef p_H
#define p_H
namespace testing{

 extern int changes_made;

 class p 
 {
   public: 
     void changed();
     void print_change();
     void print_change_ns();
   private:
     static int changes;
     int info;
};

}
#endif
</code></pre>

<p>p.cpp:</p>

<pre><code> #include "p.h"
#include&lt;iostream&gt;

using namespace testing;

int p::changes=0;

void p::changed(){
    p::changes=1;
    }

void p::print_change(){
    cout &lt;&lt; p::changes &lt;&lt; endl;
    }

void p::print_change_ns(){
    if (testing::changes_made == 1){
    cout &lt;&lt; 1 &lt;&lt; endl;
    }
    else{
    cout &lt;&lt; 0 &lt;&lt; endl;
    }
    }
</code></pre>

<p>main.cpp:</p>

<pre><code>#include&lt;iostream&gt;
#include"p.h"

using namespace std;
using namespace testing;


int main(){

p test1, test2, test3;
test3.changed();
changes_made=1;

cout &lt;&lt; "test1 ";
test1.print_change();
test1.print_change_ns();

cout &lt;&lt; "test2 ";
test2.print_change();
test2.print_change_ns();

cout &lt;&lt; "test3 ";
test3.print_change();
test3.print_change_ns();

p test4;
cout &lt;&lt; "test4 ";
test4.print_change();
test4.print_change_ns();
return 0;
}
</code></pre>

<p>I get the following error messages:</p>

<pre><code>p.o: In function `testing::p::print_change_ns()':
p.cpp:(.text+0x45): undefined reference to `testing::changes_made'
main.o: In function `main':
main.cpp:(.text+0x9b): undefined reference to `testing::changes_made'
collect2: ld returned 1 exit status
</code></pre>

<p>Any help on this would be greatly appreciated. I previously had multiple declaration errors so I introduced the #ifndef stuff, and also the extern before the variables.</p>
