itkzlib-ng on windows name mangling

I am building SimpleITK on vanilla Conda with the ITK third party zlib library. Other libraries are coming from conda and appear to use the Conda zlib library. I am seeing the following linking error on windows:

ITKTestKernel.vcxproj -> %SRC_DIR%\b\ITK-build\lib\MinSizeRel\ITKTestKernel-5.3.lib

[4136](https://github.com/SimpleITK/SimpleITKCondaRecipe/actions/runs/4797602534/jobs/8534800625#step:6:4137) 
Building Custom Rule C:/Miniconda/envs/bld/conda-bld/work/b/ITK/Modules/Core/TestKernel/src/CMakeLists.txt

[4137](https://github.com/SimpleITK/SimpleITKCondaRecipe/actions/runs/4797602534/jobs/8534800625#step:6:4138) 
itkTestDriver.cxx

[4138](https://github.com/SimpleITK/SimpleITKCondaRecipe/actions/runs/4797602534/jobs/8534800625#step:6:4139)
itkzlib-5.3.lib(deflate.obj) : error LNK2005: deflate already defined in z.lib(zlib.dll) [%SRC_DIR%\b\ITK-build\Modules\Core\TestKernel\src\itkTestDriver.vcxproj] [%SRC_DIR%\b\ITK.vcxproj]

[4139](https://github.com/SimpleITK/SimpleITKCondaRecipe/actions/runs/4797602534/jobs/8534800625#step:6:4140)
itkzlib-5.3.lib(deflate.obj) : error LNK2005: deflateEnd already defined in z.lib(zlib.dll) [%SRC_DIR%\b\ITK-build\Modules\Core\TestKernel\src\itkTestDriver.vcxproj] [%SRC_DIR%\b\ITK.vcxproj]

[4140](https://github.com/SimpleITK/SimpleITKCondaRecipe/actions/runs/4797602534/jobs/8534800625#step:6:4141)
itkzlib-5.3.lib(deflate.obj) : error LNK2005: deflateInit2_ already defined in z.lib(zlib.dll) [%SRC_DIR%\b\ITK-build\Modules\Core\TestKernel\src\itkTestDriver.vcxproj] [%SRC_DIR%\b\ITK.vcxproj]

These symbols seem to be name mangled with zlib.def.in. I don’t see where this file is configured, but I’m not familiar with these window def files.

Anyone have more insight into what is and is suppose to be occurring here?

Thanks,
Brad

ZLIB_SYMBOL_PREFIX is defined by zlib-ng here:

It is initialized by ITK here:

so all symbols in ITK’s bundled zlib should have itkzlib_ prefix.

zlib.def.in might only be used by the makefiles (not CMake), such as:

But I am not sure of this, it might be implicitly be used by something in the build system. If it is not used, we could remove it from our bundle:

Yes, they should. But the link error message appears to indicate that the symbols are not getting mangled on Windows.

I last dealt with this in Improve symbol name mangling of zlib and HDF5 · Issue #3530 · InsightSoftwareConsortium/ITK · GitHub and Add missing symbol name mangling by dzenanz · Pull Request #1322 · zlib-ng/zlib-ng · GitHub. My issues were a lot more convoluted than deflate being already defined. I suggest starting diagnosis by looking into ITK’s CMakeCache.txt.