• Advertisement
Sign in to follow this  

can't link to static library with global variables

This topic is 3388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement