开发者

extern linking problems in Microsoft Visual Studio

I have two libs that share a extern variable. In libA I have the variable declared in the header as such:

extern int Gbl;

then I define it again in the source as:

int Gbl;

next then I set Gbl=1;

in libB, I include libA's header file. And printf Gbl, expecting to get 1 here.

though unfortunately i can't even compile this since I get the error:

undefined symbol '_Gbl' referenced in ....
开发者_如何学Go

I was told that this is a linking error, but I'm not sure what to do from here


You need to compile the libB with libA included. This is done by adding -llibA to the compile line. If you don't have library options set correctly, you need to add -lpath_to_library

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜