zlib 1.2.5 – fatal error LNK1120: X unresolved externals

When trying to link program to zlib 1.2.5 static library (zlib.lib), I got the following error:
fatal error LNK1120: X unresolved externals ...

Version 1.1.3 worked without any problems. Without going into details, here is what I did – using DUMPBIN.EXE I figured out that I am using __cdecl (/Gd) Calling convention, but zlib somehow overrides it with __stdcall (/Gz). Two hours letter I found that Visual Studio 2010 solution (zlib-1.2.5\contrib\vstudio\vc10\zlibvc.sln) has definition ZLIB_WINAPI.

Removing ZLIB_WINAPI solved my problem. To remove, it go to:
zlibstat Properties – Configuration Properties – C/C++ – Preprocessor – Preprocessor Definitions

Alternatively, you can comment out ifdef block – #ifdef ZLIB_WINAPI.

One thought on “zlib 1.2.5 – fatal error LNK1120: X unresolved externals”

  1. Just had the same problem, but for me I resolved the issue by defining ZLIB_WINAPI
    #define ZLIB_WINAPI
    #include "zlib.h"

Leave a Reply

Your email address will not be published.