Reputation: 2063
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
Upvotes: 3
Views: 3505
Reputation: 1233
zlib functions are defined as ZEXPORT. if ZLIB_WINAPI is defined, then ZEXPORT is defined as __stdcall, else it has no value and all zlib function are defined by default to __cdecl.
When i compiled zlib in VS2015, ZLIB_WINAPI was defined in zlib project, and in my c++ project ZLIB_WINAPI was not defined. so my project is looking for __cdecl functions in the zlib .lib file, and the zlib .lib file is compiled as __stdcall.
to fix that, you need to tell the compiler in your project that the zlib .lib file uses __stdcall call convention.
do is by using:
#define ZLIB_WINAPI
before
#include "....\zlib.h"
in your project
Upvotes: 2