Mail Archives: djgpp/2000/07/24/08:18:44
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 T> class X {
> static T s;
> };
> template<class T> T X<T>::s = 0;
> ---------------------------------------------------------
> However, upon putting such a thing in a header file, I received a linker
> error.
>
> test.o: In function `foo<int>::blech(void)':
> test.cpp:15: undefined reference to `foo<int>::bar'
> collect2: ld returned 1 exit status
>
> Here is the test code I compiled:
>
> ---------------------------------------------------------
> // in test.h
> #include <iostream>
> using std::cout;
>
> template <class Type>
> struct foo
> {
> static Type bar;
> static void blech(void);
> };
>
> template <class Type> Type foo<Type>::bar = 33;
>
> template <class Type> inline void foo<Type>::blech(void)
> {
> cout << "Pass the bar:" << bar << endl;
> }
> ---------------------------------------------------------
> ---------------------------------------------------------
> // in test.cpp
>
> #include "test.h"
>
> void main(void)
> {
> foo<int> 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
- Raw text -