From: Tero Parvinen Newsgroups: comp.os.msdos.djgpp Subject: Undefined reference to static members Date: Mon, 21 Oct 1996 23:11:48 +0200 Organization: Helsinki University of Technology Lines: 57 Distribution: inet Message-ID: <326BE714.3019E999@mnar.tky.hut.fi> NNTP-Posting-Host: mnar.tky.hut.fi Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp I can't get djgpp to recognize static member variables. If I do a 'gcc -c file.cc' everything seems to run fine, but if I try to link the object files, I get messages complaining about undefined references. Here's a piece of code to illustrate the problem: ---CUT--- #include class CTest { public: static int a; static void SSetA(int p); void SetA(int p); int GetA(); }; void CTest::SSetA(int p) { a = p; } void CTest::SetA(int p) { a = p; } int CTest::GetA() { return a; } int main(int argc, char *argv[]) { CTest::SSetA(1); CTest test; printf("%u\n", test.GetA); test.SetA(10); printf("%u\n", test.GetA); } ---END CUT--- the output for 'gcc stest.cc' is: stest.cc(.text+0x7): undefined reference to `CTest::a' stest.cc(.text+0x23): undefined reference to `CTest::a' stest.cc(.text+0x3b): undefined reference to `CTest::a' What's wrong here? Is it a bug or am I doing something wrong? -- Tero Parvinen Tero DOT Parvinen AT hut DOT fi http://www.niksula.cs.hut.fi/~tparvine