Next: placement new syntax
Prev: Demangler
Up: User Problems
Top: Top
3.3. 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
defined BOTH method() and bar in some source file. According to the draft
ANSI standard, you must supply an initializer, such as
in one (and only one) source file.