linkage prob...

Andrea 'fwyzard' Bocci fwyzard@inwind.it
Fri Jan 3 17:01:00 GMT 2003


At 18.46 03/01/2003 +0200, Itay 'z9u2K' Duvdevani wrote:
>Hey,
>I need an "extern static const" decleration, but it is forbidden...
>at the moment, my app won't link...

No, you don't need it to be static...

The following works for me (RedHat 8.0, GCC 3.2) :
>decl.h:
>namespace a
>{
>    namespace b
>    {
>        class x;
>        // ...
>    }
>}
>
>*********
>
>x.h:
>#include "decl.h"
>class a::b::x
>{
>public:
>    // ...
>    static const int q1;
>};
>
>**********
>
>x .cpp:
>#include "x.h"
>const int a::b::x::q1 = 4;
>// ...
>
>********
>
>main.cpp:
>#include "decl.h"
>#include "x.h"
>#include <iostream>
>using namespace a;
>using namespace a::b;
>
>int main()
>{
>    std::cout << x::q1;        // will not link... g++ says:
>    // main.cpp:8: undefined reference to `a::b::x::q1[in-charge](int const&)'
>}

Couldn't compile without these correctiosn.

fwyzard 




More information about the Gcc-help mailing list