can't link to static library with global variables
hello
I have a static library with two .cpp files.
//first cpp
static int a=0;
//second cpp
extern int a;
int g()
{
a++;
}
The static library compiles fine without errors.
but when using the lib from my main application ,that is call g(), I am getting linking error:
error LNK2001: unresolved external symbol "int a" (?a@@3HA)
how to explain this?
thanks
When you define a variable with static, it creates a version with internal linkage, which means that it's only visible within that source file. This is the exact opposite of what you want. Remove the static from the global.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement