"extern const int" creates linking errors that "extern int" doesn't
Hello.
2 source files main.cpp def.cpp
main.cpp:
Code:
#include <iostream>
using namespace std;
extern const int a;
int main()
{
cout << a << endl;
}
def.cpp:
when I compile it like this:
g++ main.cpp def.cpp -c
g++ main.o def.o
I get this error:
main.o(.text+0x12b):main.cpp: undefined reference to `a'
collect2: ld returned 1 exit status
But when I remove the "const" from the extern and from the actual definition of the value, it works. Why is it so and how to avoid id?