Go to the first, previous, next, last section, table of contents.

Linker reports undefined symbols for static data members

"g++ reports undefined symbols for all my static data members when I link, even though the program works correctly for compiler XYZ. What's going on?"

The problem is almost certainly that you don't give definitions for your static data members. If you have

class Foo {
	...
	void method();
	static int bar;
};

you have only declared that there is an int named Foo::bar and a member function named Foo::method that is defined somewhere. You still need to define both method() and bar in some source file. According to the draft ANSI standard, you must supply an initializer, such as

int Foo::bar = 0;

in one (and only one) source file.


Go to the first, previous, next, last section, table of contents.