This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Static definition error in gcc-3.4.2?


gcc-3.4.2 seems to have problems with some static definitions/initializations
on Mac OSX (I am running on Mac OSX 10.3.6, Darwin 7.6.0, cctools-528.5). For
instance, the static data member in the template Foo in the following code
snippet is always undefined.
-----------------------------------------------------------
#include <cassert>


template<class TYPE>
struct Foo {
    static int s;
};

template<class TYPE>
int Foo<TYPE>::s = sizeof(TYPE);

int main()
{
assert(sizeof(char) == Foo<char>::s);
assert(sizeof(int) == Foo<int>::s);
return 0;
}
-----------------------------------------------------------
$ g++ foo.cpp
/usr/bin/ld: Undefined symbols:
Foo<char>::s
Foo<int>::s
collect2: ld returned 1 exit status
-----------------------------------------------------------
$ as -v
Apple Computer, Inc. version cctools-528.5~obj, GNU assembler version 1.38
-----------------------------------------------------------


The gcc 3.3 that Apple shipped with my box compiles, links, and runs this just
fine, as does gcc 3.4.2 on Linux and Solaris. Does anyone know what the
problem might be? Any suggestions would be greatly appreciated.


Shawn
shawne@optonline.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]