From: pavenis AT lanet DOT lv To: Tasci Synx , djgpp AT delorie DOT com Date: Mon, 24 Jul 2000 14:17:30 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Enabling Static Data in Templates Message-ID: <397C4FFA.12305.5F312@localhost> In-reply-to: <397BC997.9C504DD9@puckbell.net> X-mailer: Pegasus Mail for Win32 (v3.12c) Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On 23 Jul 2000, at 21:44, Tasci Synx wrote: > This might be a problem with djgpp, so I wanted to ask here. > > The Ansi C++ standard gives an example of a static data member in a > templated class: > --------------------------------------------------------- > template class X { > static T s; > }; > template T X::s = 0; > --------------------------------------------------------- > However, upon putting such a thing in a header file, I received a linker > error. > > test.o: In function `foo::blech(void)': > test.cpp:15: undefined reference to `foo::bar' > collect2: ld returned 1 exit status > > Here is the test code I compiled: > > --------------------------------------------------------- > // in test.h > #include > using std::cout; > > template > struct foo > { > static Type bar; > static void blech(void); > }; > > template Type foo::bar = 33; > > template inline void foo::blech(void) > { > cout << "Pass the bar:" << bar << endl; > } > --------------------------------------------------------- > --------------------------------------------------------- > // in test.cpp > > #include "test.h" > > void main(void) > { > foo test; > test.blech(); > } > --------------------------------------------------------- > > Is this a problem specific to djgpp? Is there a switch I can use to > make sure my static templated data members are created properly? > Known problem. If You are using binutils-2.10 (bnu210b.zip) and latest update of DJGPP port of gcc-2.95.2 then You can try gcc command line option - mbnu210: gcc -mbnu210 -O2 test.cpp -lstdcxx -o test.exe Perhaps it will be default sometimes, but not now... Andris