Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wbkangtc opened this issue Aug 26, 2024 · 7 comments
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Compiler Compiler support or related warnings

Comments

@wbkangtc
Copy link

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 wbkangtc added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Aug 26, 2024
Copy link

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.

@wbkangtc
Copy link
Author

So this also happens for VS2019 build with toolset v142.

@jakimmel
Copy link

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.

@thewtex thewtex added the type:Compiler Compiler support or related warnings label Sep 3, 2024
@ryanseghers
Copy link

ryanseghers commented Sep 13, 2024

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

@dzenanz
Copy link
Member

dzenanz commented Sep 16, 2024

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

@blowekamp
Copy link
Member

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

bradking added a commit to bradking/ITK that referenced this issue Nov 17, 2024
Extend the condition from commit 08bf6be (COMP: Conditionalize
insane "#define inline" in libtiff, 2013-10-07, v4.5rc01~139^2).
Newer MSVC versions need it to avoid duplicating `__ucrt_int_to_float`.

Issue: InsightSoftwareConsortium#4820
@blowekamp
Copy link
Member

closed by #4957

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Compiler Compiler support or related warnings
Projects
None yet
Development

No branches or pull requests

7 participants
@thewtex @jakimmel @blowekamp @dzenanz @ryanseghers @wbkangtc and others