ITK icon indicating copy to clipboard operation
ITK copied to clipboard

5.4 ITK Failed to build(CMake) with error LNK2005: __ucrt_int_to_float already defined

Open wbkangtc opened this issue 1 year ago • 6 comments

Description

Fails to build on CMake 3.30.1 Windows SDK version 10.0.26100.0 to target Windows 10.0.22631. [build] -- Using MSVC's dynamic CRT (/MD and /MDd) With error message

[build]     itktiff.vcxproj -> C:\TSS\build\Extern\ITK\src\ITK-build\lib\Debug\itktiff-5.4.lib
[build] itktiff-5.4.lib(tif_luv.obj) : error LNK2005: __ucrt_int_to_float already defined in itktiff-5.4.lib(tif_aux.obj) [C:\TSS\build\Extern\ITK\src\ITK-build\Modules\IO\TIFF\src\ITKIOTIFF.vcxproj] [C:\TSS\build\ITK.vcxproj]
[build] itktiff-5.4.lib(tif_color.obj) : error LNK2005: __ucrt_int_to_float already defined in itktiff-5.4.lib(tif_aux.obj) [C:\TSS\build\Extern\ITK\src\ITK-build\Modules\IO\TIFF\src\ITKIOTIFF.vcxproj] [C:\TSS\build\ITK.vcxproj]

Steps to Reproduce

  1. Attempt build.
	ExternalProject_add(ITK
	  PREFIX ${CMAKE_BINARY_DIR}/Extern/ITK
	  GIT_REPOSITORY https://github.com/InsightSoftwareConsortium/ITK.git
	  GIT_TAG v5.4.0
	  UPDATE_COMMAND ""
	  CMAKE_ARGS
		-DBUILD_EXAMPLES:BOOL=OFF
		-DBUILD_SHARED_LIBS:BOOL=ON
		-DBUILD_TESTING:BOOL=OFF
		-DCMAKE_BUILD_TYPE:STRING=${CUSTOM_BUILD_TYPE}
		-DITK_BUILD_DEFAULT_MODULES:BOOL=ON
		-DModule_ITKReview:BOOL=ON
		-DITK_LEGACY_REMOVE:BOOL=ON
		-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DEPENDENCIES_DIR}/ITK
		-DITK_USE_SYSTEM_HDF5:BOOL=OFF
		-DModule_ITKVtkGlue:BOOL=OFF
		-DHDF5_ROOT:STRING=${HDF5_ROOT}
	  INSTALL_DIR ${INSTALL_DEPENDENCIES_DIR}
	  DEPENDS HDF5
	)

Expected behavior

Build

Actual behavior

[build]     itktiff.vcxproj -> C:\TSS\build\Extern\ITK\src\ITK-build\lib\Debug\itktiff-5.4.lib
[build] itktiff-5.4.lib(tif_luv.obj) : error LNK2005: __ucrt_int_to_float already defined in itktiff-5.4.lib(tif_aux.obj) [C:\TSS\build\Extern\ITK\src\ITK-build\Modules\IO\TIFF\src\ITKIOTIFF.vcxproj] [C:\TSS\build\ITK.vcxproj]
[build] itktiff-5.4.lib(tif_color.obj) : error LNK2005: __ucrt_int_to_float already defined in itktiff-5.4.lib(tif_aux.obj) [C:\TSS\build\Extern\ITK\src\ITK-build\Modules\IO\TIFF\src\ITKIOTIFF.vcxproj] [C:\TSS\build\ITK.vcxproj]

Reproducibility

100

Versions

v5.4.0

Environment

Fails to build on CMake 3.30.1 Windows SDK version 10.0.26100.0 to target Windows 10.0.22631. [build] -- Using MSVC's dynamic CRT (/MD and /MDd) MSVC 17.10 (VS2022)

Additional Information

wbkangtc avatar Aug 26 '24 08:08 wbkangtc

Thank you for contributing an issue! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜 Also, please check existing open issues and consider discussion on the ITK Discourse. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it.

github-actions[bot] avatar Aug 26 '24 08:08 github-actions[bot]

So this also happens for VS2019 build with toolset v142.

wbkangtc avatar Aug 28 '24 00:08 wbkangtc

You can get the build to complete by adding "/FORCE:MULTIPLE" to the linker command line. TBD whether or not this causes issues in practice though.

jakimmel avatar Aug 30 '24 11:08 jakimmel

In Modules\ThirdParty\TIFF\src\itktiff\tif_config.h.in:

/* MSVC does not support C99 inline, so just make the inline keyword disappear for C. */ #ifndef __cplusplus # ifdef _MSC_VER # define inline # endif

That was apparently necessary for an older version of MSVC, but causes this problem for the version I have (Visual Studio 17.10.4, cl.exe version 19.40.33812).

That define means __ucrt_int_to_float does not get inlined despite needing to be. That symbol ends up in three of the obj files (tif_aux.obj tif_color.obj tif_luv.obj) and I get a link warning when those three obj files are linked into itktiff-5.4.lib, but that link succeeds. Then when a later step tries to link into an exe (itkTestDriver) it chokes.

I think those lines should just be removed, because it's not good to redefine a language keyword, and people should probably not be using such an old version of MSVC, and at least they should get a clear error message if they are.

Another possible fix is to change the ifdef to something like: # if defined(_MSC_VER) && _MSC_VER < 1900

(But I had trouble confirming the version of MSVC that added inline keyword support for C.)

ryanseghers avatar Sep 13 '24 21:09 ryanseghers

@blowekamp @issakomi @seanm is anyone brave enough to update bundled version of TIFF? It seems like we have some very old version of it.

dzenanz avatar Sep 16 '24 13:09 dzenanz

@dzenanz I looked into it, and yes we do. It looks like there is CMake infrastructure in the new libtiff. It also looks like VTK is maintaining a forked repo version of libtiff. Seems like there should be more knowledge around what is needed to be done to update it than what I have.

blowekamp avatar Sep 16 '24 14:09 blowekamp

closed by #4957

blowekamp avatar Nov 17 '24 21:11 blowekamp