My program (VS 2010) uses Google Buffer Protocol compiled with HAVE_ZLIB
option enabled. I compiled the latest version of zlib
and added .lib
in my project, but during linking i still got
1>libprotobuf.lib(gzip_stream.obj) : error LNK2001: unresolved external symbol _inflateEnd 1>libprotobuf.lib(gzip_stream.obj) : error LNK2001: unresolved external symbol inflateInit2 1>libprotobuf.lib(gzip_stream.obj) : error LNK2001: unresolved external symbol _inflate 1>libprotobuf.lib(gzip_stream.obj) : error LNK2001: unresolved external symbol deflateInit2 1>libprotobuf.lib(gzip_stream.obj) : error LNK2001: unresolved external symbol _deflate 1>libprotobuf.lib(gzip_stream.obj) : error LNK2001: unresolved external symbol _deflateEnd
I used dumpbin.exe /all zlib.lib
, it says:
File Type: LIBRARY
.... 245 public symbols .... 4DBE __imp__inflateInit2_@16 4DBE _inflateInit2_@16
also there are other unresolved symbols in this list.
What's wrong then? Why does the linker can't find these functions?
upd: after recompiling zlib
now it's __imp__inflateInit2_@4
__stdcall
as the default calling convention when building zlib (perhaps with/Gz
compiler switch), while the calling code expects good old__cdecl
. – Igor Tandetnik__cdecl
there, no/Gz
option in the command line arguments – fogbit@16
is the tell-tale sign of stdcall name mangling. Another thing to check: perhaps the functions are declared something likevoid ZLIBAPI inflateEnd(...)
, and the macroZLIBAPI
ends up expanding to__stdcall
in one place but to__cdecl
in another. – Igor Tandetnik_inflateEnd@4
, not@16
– fogbitinflateInit2
before, notinflateEnd
. The number after @ sign is the total number of bytes required for all function parameters, so naturally it may be different for different functions. Again, that's how __stdcall name decoration works (see "Name decoration" section of this document) – Igor Tandetnik