filipdutescu / modern-cpp-template

A template for modern C++ projects using CMake, Clang-Format, CI, unit testing and more, with support for downstream inclusion.
The Unlicense
1.69k stars 214 forks source link

[BUG] msvc runtime library not setup at all. #24

Closed Kiddinglife closed 3 years ago

Kiddinglife commented 3 years ago

Describe the bug cmake build stage failed with the error msg below:

[main] Building folder: QuicPlus 
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --build d:/VS2019/QuicPlus/build --config Debug --target all -j 24 --
[build] [1/2  50% :: 0.886] Building CXX object test\CMakeFiles\tmp_test_Tests.dir\src\tmp_test.cpp.obj
[build] [2/2 100% :: 1.036] Linking CXX executable test\tmp_test_Tests.exe
[build] FAILED: test/tmp_test_Tests.exe 
[build] cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=test\CMakeFiles\tmp_test_Tests.dir --rc="D:\Windows Kits\10\bin\10.0.19041.0\x86\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.19041.0\x86\mt.exe" --manifests  -- "D:\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64\link.exe" /nologo test\CMakeFiles\tmp_test_Tests.dir\src\tmp_test.cpp.obj  /out:test\tmp_test_Tests.exe /implib:test\tmp_test_Tests.lib /pdb:test\tmp_test_Tests.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  lib\Debug\QuicPlus.lib  D:\vcpkg\installed\x64-windows-static\debug\lib\manual-link\gtest_maind.lib  D:\vcpkg\installed\x64-windows-static\debug\lib\gtestd.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D D:\VS2019\QuicPlus\build\test && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file D:/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary D:/VS2019/QuicPlus/build/test/tmp_test_Tests.exe -installedDir D:/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""
[build] LINK Pass 1: command "D:\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64\link.exe /nologo test\CMakeFiles\tmp_test_Tests.dir\src\tmp_test.cpp.obj /out:test\tmp_test_Tests.exe /implib:test\tmp_test_Tests.lib /pdb:test\tmp_test_Tests.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console lib\Debug\QuicPlus.lib D:\vcpkg\installed\x64-windows-static\debug\lib\manual-link\gtest_maind.lib D:\vcpkg\installed\x64-windows-static\debug\lib\gtestd.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:test\CMakeFiles\tmp_test_Tests.dir/intermediate.manifest test\CMakeFiles\tmp_test_Tests.dir/manifest.res" failed (exit code 1169) with the following output:
[build] gtestd.lib(gtest-all.cc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: struct _Cvtvec __cdecl std::_Locinfo::_Getcvt(void)const " (?_Getcvt@_Locinfo@std@@QEBA?AU_Cvtvec@@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: bool __cdecl std::ios_base::good(void)const " (?good@ios_base@std@@QEBA_NXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: int __cdecl std::ios_base::flags(void)const " (?flags@ios_base@std@@QEBAHXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(void)const " (?width@ios_base@std@@QEBA_JXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(__int64)" (?width@ios_base@std@@QEAA_J_J@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::basic_streambuf<char,struct std::char_traits<char> >(void)" (??0?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAA@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.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_traits@D@std@@@std@@UEAA@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: int __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAHD@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAA_JPEBD_J@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::eback(void)const " (?eback@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::gptr(void)const " (?gptr@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::pbase(void)const " (?pbase@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::pptr(void)const " (?pptr@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::egptr(void)const " (?egptr@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::gbump(int)" (?gbump@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAAXH@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::setg(char *,char *,char *)" (?setg@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAAXPEAD00@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::epptr(void)const " (?epptr@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::setp(char *,char *)" (?setp@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAAXPEAD0@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::setp(char *,char *,char *)" (?setp@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAAXPEAD00@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::_Pninc(void)" (?_Pninc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@IEAAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.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@@UEAA@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: void __cdecl std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAAXH_N@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: char __cdecl std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: __cdecl std::basic_ios<char,struct std::char_traits<char> >::basic_ios<char,struct std::char_traits<char> >(void)" (??0?$basic_ios@DU?$char_traits@D@std@@@std@@IEAA@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: void __cdecl std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAXXZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::operator<<(int)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV01@H@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __cdecl std::basic_iostream<char,struct std::char_traits<char> >::basic_iostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *)" (??0?$basic_iostream@DU?$char_traits@D@std@@@std@@QEAA@PEAV?$basic_streambuf@DU?$char_traits@D@std@@@1@@Z) already defined in gtestd.lib(gtest-all.cc.obj)
[build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: virtual __cdecl std::basic_iostream<char,struct std::char_traits<char> >::~basic_iostream<char,struct std::char_traits<char> >(void)" (??1?$basic_iostream@DU?$char_traits@D@std@@@std@@UEAA@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
[build] libcpmtd.lib(locale0.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(locale0.obj) : error LNK2005: "void __cdecl std::_Facet_Register(class std::_Facet_base *)" (?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z) already defined in msvcprtd.lib(locale0_implib.obj)
[build] libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPEAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(bool)" (?_Init@locale@std@@CAPEAV_Locimp@12@_N@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,char const *)" (?_Locinfo_ctor@_Locinfo@std@@SAXPEAV12@PEBD@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPEAV12@@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Locimp::_New_Locimp(class std::locale::_Locimp const &)" (?_New_Locimp@_Locimp@locale@std@@CAPEAV123@AEBV123@@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(cout.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(cerr.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(locale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(locale.obj) : error LNK2005: "private: static void __cdecl std::locale::_Locimp::_Locimp_Addfac(class std::locale::_Locimp *,class std::locale::facet *,unsigned __int64)" (?_Locimp_Addfac@_Locimp@locale@std@@CAXPEAV123@PEAVfacet@23@_K@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(iosptrs.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xlock.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QEAA@H@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QEAA@XZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(wlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getdays(void)const " (?_Getdays@_Locinfo@std@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getmonths(void)const " (?_Getmonths@_Locinfo@std@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getdays(void)const " (?_W_Getdays@_Locinfo@std@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getmonths(void)const " (?_W_Getmonths@_Locinfo@std@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(xlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getdays(void)const " (?_Getdays@_Locinfo@std@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getmonths(void)const " (?_Getmonths@_Locinfo@std@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getdays(void)const " (?_W_Getdays@_Locinfo@std@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getmonths(void)const " (?_W_Getmonths@_Locinfo@std@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
[build] libcpmtd.lib(xstol.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xstoul.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xstoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xstoull.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xmtx.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xstrcoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xdateord.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xwcscoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xwcsxfrm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xgetwctype.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xtowlower.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xtowupper.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(xstrxfrm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(StlCompareStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(StlCompareStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(StlLCMapStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] libcpmtd.lib(StlLCMapStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
[build] LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
[build] test\tmp_test_Tests.exe : fatal error LNK1169: one or more multiply defined symbols found
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1

The problem is casued by the missing of setup of msvc runtime library.

To Reproduce

  1. Install vcpkg
  2. Install gtest via vcpkg.exe install gtest:x64-windows-static.
  3. Download and install vscode editor.
  4. Install c++ extension pack into the vscode editor.
  5. Git clone modern-cpp-template
  6. Open it from vscode editor
  7. Create a folder .vscode in the root folder and create a settings.json file in .vscode folder with the below content:
    {
    "cmake.configureSettings": {
    // "CMAKE_BUILD_TYPE": "Release", this does not take effetc. so use the vscode gui to control the build type
    "BUILD_SHARED_LIBS": "OFF",
    "VCPKG_TARGET_TRIPLET": "x64-windows-static",
    "CMAKE_TOOLCHAIN_FILE": "D:/vcpkg/scripts/buildsystems/vcpkg.cmake"
    }
    }

    Change D:/vcpkg/scripts/buildsystems/vcpkg.cmake to your own path.

  8. config and build the project via vscode gui.

Expected behavior config and build shoudl succeed. and tests shoudl all passed.

Desktop (please complete the following information):

Additional context I fixed up the issue by adding this line in my fork I am happy to create a PR when the issue is discussed and got alignment with the author.

filipdutescu commented 3 years ago

Hello! First of all, thanks very much for trying out the template and for opening this issue, especially since I primarily use Linux, so I might've never found it otherwise. Now regarding the actual issue.

Additional context

I fixed up the issue by adding this line in my fork I am happy to create a PR when the issue is discussed and got alignment with the author.

I would be happy to receive a PR from you, but there are some "issues" with your addition. While fixing the matter at hand, I think it introduces others.

#
# Set Multithread Runtime library for MSVC ABI
#
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

First of all, neither on Linux, nor Mac will this work, without the proper setup. I also think, as far as my knowledge goes, that most nix developers do not use VCPKG. Besides, this seems to only work for Debug. I am not familiar with this syntax/configuration, but I think it should* also be done for Release.

I have the following proposals for you, in order to get your input:

  1. CMAKE_MSVC_RUNTIME_LIBRARY must only be set if ${PROJECT_NAME}_ENABLE_VCPKG is ON.
  2. Similarly, for Release it should also be set (if it needs to be; here I would love to get your input as I'm kind of out of my league :smile:).

Now, based on your response and depending on the conclusions we reach, I think we can decide if you should open a PR (which I will be more than happy to receive :tada:) or if I should make a commit.

Kiddinglife commented 3 years ago

Hey @filipdutescu, I investigate this issue more. For your specfic feedbacks, CMAKE_MSVC_RUNTIME_LIBRARY must only be set if ${PROJECT_NAME}_ENABLE_VCPKG is ON. The RUNTIME_LIBRARY is used to by developer to customize the way how the multithread library is linked. So I think maybe the better way is to only set it if MSVC is defined. Similarly, for Release it should also be set (if it needs to be; here I would love to get your input as I'm kind of out of my league I updated my changes to cover all build types morew than debug and release and tested them locally via vscode editor gui. I think we can decide if you should open a PR (which I will be more than happy to receive 🎉) or if I should make a commit. You can do it. but please refer to my changes more or less.

The below is the v2 changes from me: Firstly I added a new option ${PROJECT_NAME}_USE_MSVC_MultiThreadDLL in StandardSettings.cmake

#
# Compiler options
#
option(${PROJECT_NAME}_WARNINGS_AS_ERRORS "Treat compiler warnings as errors." OFF)
option(${PROJECT_NAME}_USE_MSVC_MultiThreadDLL "Link dynamically-link mutithread library. This flag only take effect when it is MSVC" OFF)

Then I updated CMakeList.txt with Setup CMAKE_MSVC_RUNTIME_LIBRARY:

#
# Set project options 
#
include(cmake/StandardSettings.cmake)
include(cmake/StaticAnalyzers.cmake)
include(cmake/Utils.cmake)
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Debug")
endif()
message(STATUS "Started CMake for ${PROJECT_NAME} v${PROJECT_VERSION}...\n")
#
# Setup CMAKE_MSVC_RUNTIME_LIBRARY
#
if(MSVC)
  if( ${PROJECT_NAME}_USE_MSVC_MultiThreadDLL)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
  else()
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  endif()
  message(STATUS "Adjusted CMAKE_MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY}")
endif()
filipdutescu commented 3 years ago

So I think maybe the better way is to only set it if MSVC is defined.

You are correct, I had a brain freeze apparently haha

${PROJECT_NAME}_USE_MSVC_MultiThreadDLL

I think this can be replaced by checking if the detected compiler is MSVC. Why do we need a DLL for this, are there cases where on some Windows versions it is a DLL and on others a static lib?

Considering this comment on the exact CMake issue, I think we should not use this DLL linking.

This is a template meant to work out of the box for the majority of people, with minor tweaks, so if someone needs DLL they should manually change it (if the static lib solution is the correct one). I think a comment mentioning this above the inserted snippet is enough in this case.

The below is the v2 changes from me:

I fail to see how it covers more build types, such as release, maybe I am misunderstanding something? But, taking into consideration the comment mentioned above, it might not be an issue.

The more I think about the problem, the more I am wondering if the template should include this by default. If this error occurs only when one is using threads in their code, than I would opt out of including the changes. If it is just a must for MSVC then it should indeed be included. Otherwise, I think it might be better to omit it, since it will mean larger results after compilation.

filipdutescu commented 3 years ago

I would also move the code near the section with project dependencies, since it is a MSVC dependency as far as I can tell.

Kiddinglife commented 3 years ago

Why do we need a DLL for this, are there cases where on some Windows versions it is a DLL and on others a static lib? you can refer to the cmake official doc. there are 4 combinations for CMAKE_MSVC_RUNTIME_LIBRARY.
The example only covers two static-version runtime libraries The story is like this: I installed gtest via vcpkg and the by defaullt it uses MTd runtime library. However, the default runtime library used in my test excutable is MDd. so the build stage failed due to the inconsistency of the runtime libraries. So cmake after v3.15.0 has a new variable called CMAKE_MSVC_RUNTIME_LIBRARY to let developer have ability to specify whatever runtime libary he wants instead of the default MDd.

Kiddinglife commented 3 years ago

If it is just a must for MSVC then it should indeed be included Ny feeling is it is a must for msvc expecially when build stage fails. It does resolve an existing build problem for msvc abi and can save the developers a lots of time to get things work.

Kiddinglife commented 3 years ago

I fail to see how it covers more build types, such as release accroding to the cmake offical doc , there is postfix of Debug but there is no postfix of Release for runtime library. if it is release, then they are MultiThreaded and MultiThreadedDLL . otherwise, they are MultiThreadedDebug and MultiThreadedDebugDLL

filipdutescu commented 3 years ago

I say keep the macro, but no option to dynamically link, just statically and based on each user's specific project and setup, they should modify it as they see fit (if your project needs to use DLL, then it is not an option, rather an obligation).

In order to make it easy for others to realise this, a comment should suffice.

What do you think?

Kiddinglife commented 3 years ago

What do you think? looks good to me.

filipdutescu commented 3 years ago

used wrong default in CMakeLists.txt