[ITK-dev] Static link "error LNK2005: png_get_uint_31 already defined in png.lib", missing #define in itk_png_mangle.h?

Niels Dekker niels-xtk at xs4all.nl
Tue Apr 11 09:11:18 EDT 2017


When trying build our project, which links statically to both ITK and 
the Niftyreg library, my colleague Floris Berendsen and I encountered 
the following link error:

   >itkpng-4.10.lib(pngrutil.obj) : error LNK2005: png_get_uint_31 
already defined in png.lib(pngrutil.obj) 
[...\SuperElastix-build\Testing\Unit\selxAnyFileIOTest.vcxproj]
   >...\SuperElastix-build\bin\Debug\selxAnyFileIOTest.exe : fatal error 
LNK1169: one or more multiply defined symbols found 
[...\SuperElastix-build\Testing\Unit\selxAnyFileIOTest.vcxproj]

It appears that ITK and Niftyreg link to different versions of libpng. 
Fortunately, ITK has done name mangling for most of the libpng API 
functions, to avoid such linking errors, as we can see at 
Modules/ThirdParty/PNG/src/itkpng/itk_png_mangle.h  Now it appears that 
the function "png_get_uint_31" is also exported by libpng, but that 
function is not mangled by ITK! We could locally fix our link error by 
adding an extra #define to "itk_png_mangle.h":

     #define png_get_uint_31 itk_png_get_uint_31

Do you guys agree that that would be an appropriate fix? Could such a 
fix be added to the ITK code base?

   Kind regards, Niels

PS Our project, SuperElastix, can be found at 
https://github.com/SuperElastix/SuperElastix  (We tried to build the 
SuperBuild from the development branch.) The Nifty Reg library is from 
https://cmiclab.cs.ucl.ac.uk/mmodat/niftyreg

-- 
Niels Dekker
Scientific programmer
LKEB, Leiden University Medical Center, Netherlands


More information about the Insight-developers mailing list