problem with extern variable

Posted by sksingh73 on Stack Overflow See other posts from Stack Overflow or by sksingh73
Published on 2010-05-24T17:16:36Z Indexed on 2010/05/24 17:21 UTC
Read the original article Hit count: 216

Filed under:
|
|

I have got 2 cpp files & a header file, which I have included in both cpp files. It's like this:

abc.h

extern uint32_t key;

a.cpp

#include "abc.h"
uint32_t key;
int main
{
.............
}

b.cpp #include "abc.h"

int main
{
printf("Key: %.8x\n", key);
.............
}

Now when I compile a.cpp, there is no error. but when i compile b.cpp it gives error "undefined reference to `key'". Please help me in finding the problem in this code.

© Stack Overflow or respective owner

Related posts about c++

Related posts about variable