[Cpp] MSVC Build issues with runtime Library type MD

Does XGBOOST not support MD runtime Library on MSVC?

I see that we force static runtime for MSVC by calling msvc_use_static_runtime() from cmake/Utils.cmake
e.g.


or CMakeLists.txt#L332
or …/master/src/CMakeLists.txt#L32

With my limited understanding, this creates issue with applications as default runtime is MD and hence resulting into link errors.

I am building XGBOOST as a static c++ library i.e. BUILD_STATIC_LIB = ON

When I try to build my application while linking against this xgboost.lib, I get runtime Library mismatch errors.
e.g.
xgboost.lib(learner.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MT_StaticRelease’ doesn’t match value ‘MD_DynamicRelease’ in xyz.obj [C:\dev\projects\hap.xgboost\apps\build\xyz.vcxproj]


xgboost.lib(random.obj) : error LNK2038: mismatch detected for ‘RuntimeLibrary’: value ‘MT_StaticRelease’ doesn’t match value ‘MD_DynamicRelease’ in xyz.obj [C:\dev\projects\hap.xgboost\apps\build\xyz.vcxproj]

(xyz is the name of my test application)

While debugging this, I found the forceful use of static runtime Library in cmake of xgboost, leading to mismatch.
Hence pointed it out.

Please let me know if you need any further information

Already created an issue on github https://github.com/dmlc/xgboost/issues/7163. Posting here for detailed discussion and inputs from other users