Sign in to follow this  
elih1

can't link to static library with global variables

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this