Trying to compile zlib 1.2.13 for windows. Cannot resolve linker error below, any help is appreciated!
Creating library zdll.lib and object zdll.exp
[2023-08-09T07:50:09.645Z] if exist zlib1.dll.manifest mt -nologo -manifest zlib1.dll.manifest -outputresource:zlib1.dll;2
[2023-08-09T07:50:10.227Z] cl -c -I. -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_NO_CRT_STDIO_INLINE -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" ./test\example.c
[2023-08-09T07:50:10.227Z] example.c
[2023-08-09T07:50:10.227Z] link -nologo -debug -incremental:no -opt:ref example.obj zlib.lib
[2023-08-09T07:50:10.227Z] example.obj : error LNK2019: unresolved external symbol __imp____acrt_iob_func referenced in function _main
[2023-08-09T07:50:10.227Z] example.exe : fatal error LNK1120: 1 unresolved externals
[2023-08-09T07:50:10.227Z] NMAKE : fatal error U1077: '"c:\program files (x86)\microsoft visual studio 12.0\vc\bin\link.EXE"' : return code '0x460'
[2023-08-09T07:50:10.227Z] Stop.
my lib environment variables:
$env:lib += ";c:\program files (x86)\microsoft visual studio 12.0\vc\lib"
$env:lib += ";c:\program files (x86)\windows kits\10\lib\10.0.19041.0\um\x86"
$env:lib += ";c:\program files (x86)\windows kits\10\lib\10.0.19041.0\um\x64"
$env:lib += ";c:\program files (x86)\windows kits\10\lib\10.0.19041.0\ucrt\x86"
$env:lib += ";c:\program files (x86)\windows kits\10\lib\10.0.19041.0\ucrt\x64"
$env:lib += ";c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\lib\x86"
$env:lib += ";c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\lib\x64"
In general, code built with different versions of the Visual C++ compiler are not link-compatible. There are specific cases where it works, but mostly just import libraries for DLLs using the C ABI (i.e. stuff like KERNEL32.LIB
, etc.)
The Visual C++ team has been working really hard to support 'forward link compatibility' for VS 2015 Update 3 - VS 2022. See Microsoft Learn. VS 2013 is NOT part of this promise.
You should look at using a package manager like VCPKG for zlib which ensures you are using the matching compiler toolset.