Undefined reference to a static member

kakush picture kakush · Feb 2, 2012 · Viewed 72.1k times · Source

I'm using a cross compiler. My code is:

class WindowsTimer{
public:
  WindowsTimer(){
    _frequency.QuadPart = 0ull;
  } 
private:
  static LARGE_INTEGER _frequency;
};

I get the following error:

undefined reference to `WindowsTimer::_frequency'

I also tried to change it to

LARGE_INTEGER _frequency.QuadPart = 0ull;

or

static LARGE_INTEGER _frequency.QuadPart = 0ull;

but I'm still getting errors.

anyone knows why?

Answer

Ed Heal picture Ed Heal · Feb 2, 2012

You need to define _frequency in the .cpp file.

i.e.

LARGE_INTEGER WindowsTimer::_frequency;