Errors while building a static libtorch

I’m trying to build a static libtorch in a brand new conda environment, following the instruction in the README.md in the repository.

It builds during a while, but up to a point I have a bunch of errors:

onnx.lib(defs.cc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary' : value 'MT_StaticRelease
' doesn't match value 'MD_DynamicRelease' in core.obj 
onnx.lib(old.cc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary' : value 'MT_StaticRelease'
 doesn't match value 'MD_DynamicRelease' in core.obj

etc… it goes like this during a while, then a bunch of already defined symbols:

msvcprt.lib(MSVCP140.dll) : error LNK2005: "protected: __cdecl std::basic_streambuf<char,struct std::char_trait
s<char> >::basic_streambuf<char,struct std::char_traits<char> >(void)" (??0?$basic_streambuf@DU?$char_traits@D@
std@@@std@@IEAA@XZ) already defined in onnx.lib(defs.cc.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: virtual __cdecl std::basic_streambuf<char,struct std::char_
traits<char> >::~basic_streambuf<char,struct std::char_traits<char> >(void)" (??1?$basic_streambuf@DU?$char_tra
its@D@std@@@std@@UEAA@XZ) already defined in onnx.lib(defs.cc.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: virtual __cdecl std::basic_ios<char,struct std::char_traits
<char> >::~basic_ios<char,struct std::char_traits<char> >(void)" (??1?$basic_ios@DU?$char_traits@D@std@@@std@@U
EAA@XZ) already defined in onnx.lib(defs.cc.obj) [C:\Work\pytorch\pytorch_static\pytorch\build\caffe
2\torch\lib\libshm_windows\shm.vcxproj]
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: virtual __cdecl std::basic_ostream<char,struct std::char_tr
aits<char> >::~basic_ostream<char,struct std::char_traits<char> >(void)" (??1?$basic_ostream@DU?$char_traits@D@
std@@@std@@UEAA@XZ) already defined in onnx.lib(defs.cc.obj) [C:\Work\pytorch\pytorch_static\pytorch
\build\caffe2\torch\lib\libshm_windows\shm.vcxproj]

The output is really similar to this message in that issue:

The Runtime Library errors really puzzle me, am I setting some flags wrong? I am not setting any flag that has anything to do with /MT or /MD though.