Well, I have done it along with VS 2017. But as far as I understand both VS 2015 and VS 2017 use the VCRUNTIME140.DLL
, so no worries here.
It is divided into two steps:
1. Creating an import library for VCRUNTIME140.DLL
:
This is done by doing the following:
mkdir scratch; cd scratch
cp C:/Windows/System32/vcruntime140.dll .
dumpbin /exports vcruntime140.dll > exports.txt
echo LIBRARY VCRUNTIME140 > vcruntime140.def
echo EXPORTS >> vcruntime140.def
tail +20 exports.txt | head -n -10 | awk '{print $4}' >> vcruntime140.def
lib /def:vcruntime140.def /out:libvcruntime140.a /machine:x86
cp libvcruntime140.a $(MINGW_ROOT)/i686-w64-mingw32/lib
2. Change the way MinGW GCC operates to link against VCRUNTIME140
and UCRT
instead of MSVCRT
gcc -dumpspecs > $(MINGW_ROOT)/lib/gcc/i686-w64-mingw32/$(GCC_VERSION)/specs
- Add
-D_UCRT
to cpp
and cc1plus
sections of the specs file. This will prevent undefined references linking errors for the scanf
functions family. Check my other question.
- Replace
-lmsvcrt
to -lvcruntime140 -lucrt
in the libgcc
section of the specs file.
Please exchange $(MINGW_ROOT)
with the location of where u have MinGW.
Notes:
- The platform signature part,
i686-w64-mingw32
, within the paths I included may differ for your case. I believe based on the architecture. So you may have to modify that accordingly.
- You need to use a relatively new MinGW that has
libucrt.a
in the $(MINGW_ROOT)/i686-w64-mingw32/lib folder. I am using MinGW 7.0.0 with GCC 7.4.0.