0

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"
Marisol
  • 117
  • 1
  • 7
  • 1
    Does this answer your question? [unresolved external symbol \_\_imp\_\_fprintf and \_\_imp\_\_\_\_iob\_func, SDL2](https://stackoverflow.com/questions/30412951/unresolved-external-symbol-imp-fprintf-and-imp-iob-func-sdl2) – Raymond Chen Aug 09 '23 at 13:00
  • 1
    https://learn.microsoft.com/en-us/cpp/porting/visual-cpp-change-history-2003-2015?view=msvc-170&redirectedfrom=MSDN#stdio_and_conio – Raymond Chen Aug 09 '23 at 13:01
  • @RaymondChen thank you, but not really, I added $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"paths to legacy_stdio_definitions.lib, but it didn't help. I left a comment there as well – Marisol Aug 09 '23 at 13:05
  • You have to link the library by name. Just mentioning its path is insufficient. The linker does not try every library on the path. The path is for finding libraries you have named. – Raymond Chen Aug 09 '23 at 14:52
  • 1
    Also, it makes no sense listing both x86 and x64 paths. That's like mixing left handed and right handed screws in the same drawer. – Raymond Chen Aug 09 '23 at 14:53
  • 1
    Linking from the lib directory of "microsoft visual studio 12.0" (aka VS2013) is not a good idea and practically guarantees you get this link error. It is not obvious which VS version you actually use and where zlib.lib came from, so concrete advice is hard to give. Cold hard rules are that you must use the exact same toolset for every source file and .lib you link. Using the DLL version of zlib can isolate the dependencies better. – Hans Passant Aug 09 '23 at 22:58

1 Answers1

1

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.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81