alicevision/popsift

[bug] Runtime

granger35 opened this issue · 6 comments

Describe the bug
Debug Multithread runtime library in debug (/MDd) mode replaced by the release one (/MD) which result in a link error.

To Reproduce
Steps to reproduce the behavior:

  1. CMake for Visual Studio 2019, arch x64 and BUILD_SHARED_LIBS=True, PopSift_BUILD_EXAMPLES=False
  2. Load the .sln in Visual Studio 2019,
  3. rebuild in debug mode for x64,
  4. See warning related to substitution of /MDd by /MD and the final error message

Expected behavior
When building in debug mode, warnings inform that the Multithread runtime library in debug mode (/MDd) is substituted by the realase one (/MD). This results in a link error LNK2038 avoiding to build popsift in debug mode.
In Visual Studio, by forcing /MD in the project settings (C/C++- Code generation) in debug mode, the project builds.

Log
warning message:

2>cl  : Ligne de commande warning D9025 : substitution de '/MDd' par '/MD'

error message:

2>popsift_generated_features.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_features.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_sift_constants.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_sift_constants.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_sift_conf.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_sift_conf.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_gauss_filter.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_gauss_filter.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_image.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_image.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_sift_pyramid.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_sift_pyramid.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_sift_octave.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_sift_octave.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_pyramid_build.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_pyramid_build.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_pyramid_build_aa.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_pyramid_build_aa.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_pyramid_build_ai.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_pyramid_build_ai.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_pyramid_build_ra.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_pyramid_build_ra.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_pyramid_fixed.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_pyramid_fixed.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_sift_extremum.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_sift_extremum.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_extrema.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_extrema.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_orientation.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_orientation.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_filtergrid.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_filtergrid.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_sift_desc.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_sift_desc.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_desc_loop.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_desc_loop.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_desc_iloop.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_desc_iloop.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_desc_grid.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_desc_grid.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_desc_igrid.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_desc_igrid.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_s_desc_notile.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_s_desc_notile.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_assist.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_assist.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_plane_2d.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_plane_2d.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_write_plane_2d.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_write_plane_2d.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_debug_macros.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_debug_macros.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>popsift_generated_device_prop.cu.obj : error LNK2038: discordance détectée pour '_ITERATOR_DEBUG_LEVEL' : la valeur '0' ne correspond pas à la valeur '2' in popsift.obj
2>popsift_generated_device_prop.cu.obj : error LNK2038: discordance détectée pour 'RuntimeLibrary' : la valeur 'MD_DynamicRelease' ne correspond pas à la valeur 'MDd_DynamicDebug' in popsift.obj
2>   Création de la bibliothèque C:/Dev/popsift/build/src/Debug/popsiftd.lib et de l'objet C:/Dev/popsift/build/src/Debug/popsiftd.exp
2>LINK : warning LNK4098: conflit entre la bibliothèque par défaut 'MSVCRT' et les autres bibliothèques ; utilisez /NODEFAULTLIB:library
2>C:\Dev\popsift\build\Windows-AMD64\Debug\popsiftd.dll : fatal error LNK1319: 54 discordances détectées

Desktop

  • OS: Windows 10
  • PopSift version: branch develop (similar behaviour on v1.0.0-rc3)
  • CUDA: 11.3
  • Visual studio: 2019
  • Architecture: x64
  • CMake options: BUILD_SHARED_LIBS = True, Debug mode

The debug mode is covered here

popsift/CMakeLists.txt

Lines 134 to 148 in 9dd7ae4

# this is to ensure that on MSVC the flags for the linker are properly propagate even to the intermediate
# linking step. This seems not the case e.g. on vcpkg using ninja build.
if(MSVC)
if(BUILD_SHARED_LIBS)
set(PopSift_MVSC_LINKER "/MD")
else()
set(PopSift_MVSC_LINKER "/MT")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(PopSift_MVSC_LINKER "${PopSift_MVSC_LINKER}d")
endif()
list(APPEND CUDA_NVCC_FLAGS -Xcompiler ${PopSift_MVSC_LINKER})
endif()
# default stream per-thread implies that each host thread has one non-synchronizing 0-stream

It has been tested in vcpkg for every combination static/dynamic debug/release and there was no problem there
microsoft/vcpkg#10979

Could it be that it is "DEBUG" instead of "Debug"?

Thank you simogasp for your feedback.
It is "Debug". I have installed popsift with vcpkg, and everything was working perfectly. But we would like to create a conan recipe to have a common dependency manager whatever the targeted platform. Our conan recipe works well for Ubuntu with gcc, but we have this issue on MSVC, and when testing the build manually, we had the previous error related to uncompatible runtime library. Indeed, looking at the CMakeLists.txtx file, flags seems well set, and we do not explain why the runtime library is substituted during building step.

Just to be sure, you are getting this when building popsift, not when building your project that links to popsift?

With your Conan recipe, are you using ninja to build or are you generating the VS solution etc?
Now that I think about it, the tests in vcpkg only use ninja and I didn't test the build directly in Visual Studio. I will try to test that to see if I can reproduce the problem.

BTW it's very nice and interesting that you are writing a conan recipe!
If you can, do not hesitate to share it, it will be another simple way for the users to have pre-built binaries!

Yes, it is when building popsfit project, and yes again with VS, not with ninja.
Keep me inform if you reproduce the problem on VS, and for sure, we will share the conan recipe as soon as it works.

It is actually broken when building from VS :-(

Could you try to replace these lines from the cmake snippet above

   if(CMAKE_BUILD_TYPE STREQUAL "Debug") 
       set(PopSift_MVSC_LINKER "${PopSift_MVSC_LINKER}d") 
   endif() 
   list(APPEND CUDA_NVCC_FLAGS   -Xcompiler ${PopSift_MVSC_LINKER})

with this ones

  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    list(APPEND CUDA_NVCC_FLAGS_DEBUG   -Xcompiler ${PopSift_MVSC_LINKER}d)
  else()
    list(APPEND CUDA_NVCC_FLAGS_RELEASE   -Xcompiler ${PopSift_MVSC_LINKER})
  endif()

That should be a proper way to init the flags.

Thank you, it does the job.
You can find the conan recipe on the following link:
https://github.com/SolarFramework/conan-solar/tree/master/recipes/popsift/1.0.0
You can create a package by calling for shared release version:
conan create . popsift/1.0.0-rc3@ --build=missing -o shared=True
and
conan create . popsift/1.0.0-rc3@ --build=missing -o shared=True -s build_type=Debug
for debug one.

We have also conan packages hosted on our public artifactory. To directly install popsift, here is the command:
conan remote add conan-solar https://artifact.b-com.com/api/conan/solar-conan-local
to add our conan remote, and then:
conan install popsift/1.0.0-rc3@conan-solar/stable --build=missing -o shared=True and for debug mode -s build_type=Debug
Ideally, an upload of this recipe on the official conan-center-index or at least on the conan-community would be great for your community.