InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.4k stars 661 forks source link

[ITK 5.1] Not building with external HDF5 #1799

Closed Neumann-A closed 3 years ago

Neumann-A commented 4 years ago

Description

Linker error due to missing HDF5 symbols

[1462/4340] cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\Hostx64\x64\link.exe  Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir\itkHDF5ImageIOFactory.cxx.obj Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir\itkHDF5ImageIO.cxx.obj  /out:bin\ITKIOHDF5-5.1.dll /implib:lib\ITKIOHDF5-5.1.lib /pdb:bin\ITKIOHDF5-5.1.pdb /dll /version:1.0 /nologo  /machine:x64  /nologo  /debug /INCREMENTAL  lib\ITKIOImageBase-5.1.lib  D:\qt2\installed\x64-windows\debug\lib\zlibd.lib  lib\ITKCommon-5.1.lib  lib\itksys-5.1.lib  ws2_32.lib  dbghelp.lib  psapi.lib  lib\ITKVNLInstantiation-5.1.lib  lib\itkvnl_algo-5.1.lib  lib\itkvnl-5.1.lib  lib\itkv3p_netlib-5.1.lib  lib\itknetlib-5.1.lib  lib\itkvcl-5.1.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
FAILED: bin/ITKIOHDF5-5.1.dll lib/ITKIOHDF5-5.1.lib 
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\Hostx64\x64\link.exe  Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir\itkHDF5ImageIOFactory.cxx.obj Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir\itkHDF5ImageIO.cxx.obj  /out:bin\ITKIOHDF5-5.1.dll /implib:lib\ITKIOHDF5-5.1.lib /pdb:bin\ITKIOHDF5-5.1.pdb /dll /version:1.0 /nologo  /machine:x64  /nologo  /debug /INCREMENTAL  lib\ITKIOImageBase-5.1.lib  D:\qt2\installed\x64-windows\debug\lib\zlibd.lib  lib\ITKCommon-5.1.lib  lib\itksys-5.1.lib  ws2_32.lib  dbghelp.lib  psapi.lib  lib\ITKVNLInstantiation-5.1.lib  lib\itkvnl_algo-5.1.lib  lib\itkvnl-5.1.lib  lib\itkv3p_netlib-5.1.lib  lib\itknetlib-5.1.lib  lib\itkvcl-5.1.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
LINK Pass 1: command "C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\Hostx64\x64\link.exe Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir\itkHDF5ImageIOFactory.cxx.obj Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir\itkHDF5ImageIO.cxx.obj /out:bin\ITKIOHDF5-5.1.dll /implib:lib\ITKIOHDF5-5.1.lib /pdb:bin\ITKIOHDF5-5.1.pdb /dll /version:1.0 /nologo /machine:x64 /nologo /debug /INCREMENTAL lib\ITKIOImageBase-5.1.lib D:\qt2\installed\x64-windows\debug\lib\zlibd.lib lib\ITKCommon-5.1.lib lib\itksys-5.1.lib ws2_32.lib dbghelp.lib psapi.lib lib\ITKVNLInstantiation-5.1.lib lib\itkvnl_algo-5.1.lib lib\itkvnl-5.1.lib lib\itkv3p_netlib-5.1.lib lib\itknetlib-5.1.lib lib\itkvcl-5.1.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir/intermediate.manifest Modules\IO\HDF5\src\CMakeFiles\ITKIOHDF5.dir/manifest.res" failed (exit code 1120) with the following output:
   Creating library lib\ITKIOHDF5-5.1.lib and object lib\ITKIOHDF5-5.1.exp
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol H5open referenced in function "public: virtual bool __cdecl itk::HDF5ImageIO::CanReadFile(char const *)" (?CanReadFile@HDF5ImageIO@itk@@UEAA_NPEBD@Z)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol H5check_version referenced in function "public: virtual bool __cdecl itk::HDF5ImageIO::CanReadFile(char const *)" (?CanReadFile@HDF5ImageIO@itk@@UEAA_NPEBD@Z)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol H5Aexists referenced in function "bool __cdecl itk::`anonymous namespace'::doesAttrExist(class H5::H5Object const &,char const * const)" (?doesAttrExist@?A0x9346111f@itk@@YA_NAEBVH5Object@H5@@QEBD@Z)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol H5Fis_hdf5 referenced in function "public: virtual bool __cdecl itk::HDF5ImageIO::CanReadFile(char const *)" (?CanReadFile@HDF5ImageIO@itk@@UEAA_NPEBD@Z)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol "public: char const * __cdecl H5::Exception::getCDetailMsg(void)const " (?getCDetailMsg@Exception@H5@@QEBAPEBDXZ) referenced in function __catch$?ReadImageInformation@HDF5ImageIO@itk@@UEAAXXZ$0
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol "public: class H5::IdComponent & __cdecl H5::IdComponent::operator=(class H5::IdComponent const &)" (??4IdComponent@H5@@QEAAAEAV01@AEBV01@@Z) referenced in function "public: class H5::H5Location & __cdecl H5::H5Location::operator=(class H5::H5Location const &)" (??4H5Location@H5@@QEAAAEAV01@AEBV01@@Z)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol "public: __cdecl H5::DataSpace::DataSpace(enum H5S_class_t)" (??0DataSpace@H5@@QEAA@W4H5S_class_t@@@Z) referenced in function "public: virtual void __cdecl itk::HDF5ImageIO::Read(void *)" (?Read@HDF5ImageIO@itk@@UEAAXPEAX@Z)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol "public: __cdecl H5::DataSpace::DataSpace(int,unsigned __int64 const *,unsigned __int64 const *)" (??0DataSpace@H5@@QEAA@HPEB_K0@Z) referenced in function "public: virtual void __cdecl itk::HDF5ImageIO::WriteImageInformation(void)" (?WriteImageInformation@HDF5ImageIO@itk@@UEAAXXZ)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol "public: int __cdecl H5::DataSpace::getSimpleExtentDims(unsigned __int64 *,unsigned __int64 *)const " (?getSimpleExtentDims@DataSpace@H5@@QEBAHPEA_K0@Z) referenced in function "public: virtual void __cdecl itk::HDF5ImageIO::ReadImageInformation(void)" (?ReadImageInformation@HDF5ImageIO@itk@@UEAAXXZ)
itkHDF5ImageIO.cxx.obj : error LNK2019: unresolved external symbol "public: int __cdecl H5::DataSpace::getSimpleExtentNdims(void)const " (?getSimpleExtentNdims@DataSpace@H5@@QEBAHXZ) referenced in function "public: virtual void __cdecl itk::HDF5ImageIO::ReadImageInformation(void)" (?ReadImageInformation@HDF5ImageIO@itk@@UEAAXXZ)

Steps to Reproduce

Clone https://github.com/Neumann-A/vcpkg/tree/update_itk_51 just run (after bootstrapping vcpkg of course) `./vcpkg.exe install vtk[vtkm,python,qt,paraview,atlmfc] itk[vtk,python]

`

Versions

5.1

Environment

vcpkg/windows

Additional Information

config-x64-windows-dbg-out.log install-x64-windows-dbg-out.log

Additional Information

<removed mentioned in #1696 keep focus here on related issue>

Probably related to: https://github.com/InsightSoftwareConsortium/ITK/blob/7900a8b6d63ec8201405eff3b46c8d2a4e563c45/CMake/ITKModuleMacros.cmake#L160-L168 and https://github.com/InsightSoftwareConsortium/ITK/blob/7900a8b6d63ec8201405eff3b46c8d2a4e563c45/Modules/IO/HDF5/CMakeLists.txt#L2

The following is also a very bad idea if your _LIBRARIES are not all targets (due to optimized/debug keywords): https://github.com/InsightSoftwareConsortium/ITK/blob/7900a8b6d63ec8201405eff3b46c8d2a4e563c45/CMake/ITKModuleMacros.cmake#L166

If it is all targets probably rename it to _TARGETS instead

thewtex commented 4 years ago

This could be related to the HDF5 version.

Neumann-A commented 4 years ago

This could be related to the HDF5 version.

Version is 1.10.5 Probably related to: https://github.com/InsightSoftwareConsortium/ITK/blob/ee2ab9c973e66616cc2132f9a96fcf7763a6b94d/Modules/ThirdParty/HDF5/CMakeLists.txt#L35-L40 And HDF5_CXX_(SHARED|STATIC)_LIBRARY as well as HDF5_C_(SHARED|STATIC)_LIBRARY not being defined in the hdf5config.cmake. I replaced it with the targets and it works now. #1803 seems also be solved by it. As such always try to link targets if they exists or at least check the existence of the variables before linking nothing.....

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

KrisThielemans commented 3 years ago

I have another error when building with an external HDF5 (ITK 5.1.2, HDF5 1.8.12 built from source and found via HDF5_ROOT , CMake 3.19.2, VS 2019):

2>LINK : fatal error LNK1104: cannot open file 'hdf5_cpp.lib' [C:\Users\krisf\Documents\devel\buildVC\SIRF-SuperBuild\builds\ITK\build\Modules\IO\HDF5\src\ITKIOHDF5.vcxproj]

This occurs 3 times (other occurrences are ITKIOMINC and ITKIOTransformHDF5).

Building with verbose shows for instance

Link:
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\link.exe /ERR
  ORREPORT:QUEUE /OUT:"C:\Users\krisf\Documents\devel\buildVC\SIRF-SuperBuild\builds\ITK\build\bin\RelWithDebInfo\ITKIO
  TransformHDF5-5.1.dll" /INCREMENTAL /NOLOGO "..\..\..\..\lib\RelWithDebInfo\ITKIOTransformBase-5.1.lib" hdf5_cpp.lib
  hdf5.lib "..\..\..\..\lib\RelWithDebInfo\ITKTransformFactory-5.1.lib" "..\..\..\..\lib\RelWithDebInfo\ITKTransform-5.
  1.lib" "..\..\..\..\lib\RelWithDebInfo\ITKCommon-5.1.lib" "..\..\..\..\lib\RelWithDebInfo\itksys-5.1.lib" ws2_32.lib
  dbghelp.lib psapi.lib "..\..\..\..\lib\RelWithDebInfo\ITKVNLInstantiation-5.1.lib" "..\..\..\..\lib\RelWithDebInfo\it
  kvnl_algo-5.1.lib" "..\..\..\..\lib\RelWithDebInfo\itkvnl-5.1.lib" "..\..\..\..\lib\RelWithDebInfo\itkv3p_netlib-5.1.
  lib" "..\..\..\..\lib\RelWithDebInfo\itkvcl-5.1.lib" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32
  .lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /man
  ifest:embed /DEBUG /PDB:"C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/builds/ITK/build/bin/RelWithDebInfo/I
  TKIOTransformHDF5-5.1.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/krisf/Documents/devel
  /buildVC/SIRF-SuperBuild/builds/ITK/build/lib/RelWithDebInfo/ITKIOTransformHDF5-5.1.lib" /MACHINE:X64  /machine:x64 /
  DLL ITKIOTransformHDF5.dir\RelWithDebInfo\itkHDF5TransformIO.obj
  ITKIOTransformHDF5.dir\RelWithDebInfo\itkHDF5TransformIOFactory.obj

Note the "bare" filenames for the HDF5 libraries, which is wrong as they are not in a system location. In fact, I have to set the location by passing HDF5_ROOT. Setting HDF5_FIND_DEBUG=ON gives the following output of cmake (showing only the HDF5 output):

-- HDF5_DIR: HDF5_DIR-NOTFOUND
-- HDF5_DEFINITIONS: -DH5_BUILT_AS_DYNAMIC_LIB
-- HDF5_INCLUDE_DIRS: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/include
-- HDF5_LIBRARIES: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/lib/hdf5_cpp.lib;C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/lib/hdf5.lib
-- HDF5_HL_LIBRARIES:
-- HDF5_CXX_DEFINITIONS:
-- HDF5_CXX_INCLUDE_DIR: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/include
-- HDF5_CXX_INCLUDE_DIRS: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/include
-- HDF5_CXX_LIBRARY:
-- HDF5_CXX_LIBRARIES: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/lib/hdf5_cpp.lib;C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/lib/hdf5.lib
-- HDF5_CXX_HL_LIBRARY:
-- HDF5_CXX_HL_LIBRARIES:
-- HDF5_C_DEFINITIONS:
-- HDF5_C_INCLUDE_DIR: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/include
-- HDF5_C_INCLUDE_DIRS: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/include
-- HDF5_C_LIBRARY:
-- HDF5_C_LIBRARIES: C:/Users/krisf/Documents/devel/buildVC/SIRF-SuperBuild/INSTALL/lib/hdf5.lib
-- HDF5_C_HL_LIBRARY:
-- HDF5_C_HL_LIBRARIES:

Note that I have no problems with ITK 4.13.1. (I cannot try with ITK 5.0 as https://github.com/InsightSoftwareConsortium/ITK/pull/1165 wasn't merged yet).

I agree with @Neumann-A that ITK really should use the targets when they exist. Sadly, I have no idea on how to do this for ITK.

KrisThielemans commented 3 years ago

I agree with @Neumann-A that ITK really should use the hdf5::hdf5 targets, certainly from CMake 3.10 when some things were fixed in FindHDF5.cmake. Sadly, I have no idea on how to do this for ITK.

I see this was discussed here https://github.com/InsightSoftwareConsortium/ITK/pull/1696#issuecomment-624791166

KrisThielemans commented 3 years ago

CMake 3.19.0 introduced hdf5::hdf5 etc targets, not called the same as the HDF5 config variables. See this discussion for my current understanding of naming.