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

Building Custom Rule C:/Miniconda/envs/bld/conda-bld/work/b/ITK/Modules/Core/TestKernel/src/CMakeLists.txt


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]

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]

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 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?


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. 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.