[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Linker can't find constants
From: |
Cary |
Subject: |
Linker can't find constants |
Date: |
Tue, 30 Jun 2009 13:53:31 -0700 (PDT) |
User-agent: |
G2/1.0 |
The following code compiles, but the linker complains of an undefined
reference. If I comment out the line with *xx* it will link. Is this
a known and/or fixed bug in later versions of gcc?
SLES 10.2
gcc --version gcc (GCC) 4.1.2 20070115 (SUSE Linux)
replace.cpp:
#include <algorithm>
#include <vector>
class A
{
private:
const static int k1 = 1;
std::vector<int> mv;
public:
A(int p);
};
A::A(int p) :
mv(1,p)
{
int x = mv.back() + k1; // k1 ok here
std::replace(mv.begin(), mv.end(), 0, k1); // *xx* linker
can't find k1 here
}
int main(int argc, char **argv)
{
A a(0);
return 0;
}
> g++ replace.cpp
/tmp/ccIdfZfH.o: In function `A::A(int)':
replace.cpp:(.text+0xb8): undefined reference to `A::k1'
/tmp/ccIdfZfH.o: In function `A::A(int)':
replace.cpp:(.text+0x1f2): undefined reference to `A::k1'
collect2: ld returned 1 exit status
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Linker can't find constants,
Cary <=