unresolved external symbol __imp__... when I want to link a static library

Today I build an OpenGL tutorial project with GLEW in visual studio 14 (2015). I don't want to deal with "where to put the dlls" things. So I build the static library to use : $(SolutionDir)..\dependency\glew-2.0.0\lib\Debug\Win32\glew32sd.lib

But the linker error happens: ... unresolved external symbol __imp__glewInit@0 ... and lots of other "__imp__..." unresolved symbols (which are omitted here).

Why?

Let's check the symbols in glew32sd.lib:

Open the Developer Command Prompt and type in:dumpbin /symbols glew32sd.lib > a.txt (> a.txt means redirect the console output to the file a.txt)

Search the string "__imp__glewInit@0" in “a.txt” (nodepad++ is my first choice on windows). What do you get? Well, nothing. But I think it's exactly the reason why the linker complains.

I skimmed a.txt for a while and decided to search "glewinit". In the finding results, I noticed a different but similar symbol named "_glewInit@0" which is marked as "External" ( "External" here corresponds to non-static global functions/variables I think). You may have noticed that they both have a sub-string "glewInit@0", one with prefix "__imp__" and one with prefix "_".


So, strangely enough, why are they not the same?why did the compiler expect "__imp__glewInit@0" while the static library we built with the same tool chain offers "_glewInit@0" ?

If you see the "glewinit" function declaration in the glew.h, it is:

GLEWAPI GLenum GLEWAPIENTRY glewInit (void);

And "GLEWAPI" is defined as:

#ifdef GLEW_STATIC
#  define GLEWAPI extern
#else
#  ifdef GLEW_BUILD
#    define GLEWAPI extern __declspec(dllexport)
#  else
#    define GLEWAPI extern __declspec(dllimport)
#  endif
#endif


I have never defined GLEW_STATIC. And GLEWAPI is replaced with extern __declspec(dllimport).

I guess that's the reason why our compiler expects "__imp__glewInit@0". (__imp__ probably means dllimport) And I'm right:

After I add GLEW_STATIC to C/C++ -> Preprocessor -> Preprocessor Definitions, it get solved.

The same argument applies to freeglut.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值