Linker errors in CMake project

I have a large CMake project, using the latest Develop branch, which is set up more or less from the AudioPlugin CMake example. When I build it using CMake 3.22, I get the following Linker errors.

C:\...\out\build\x64-Debug\juce_audio_plugin_client_VST3.cpp.obj : error LNK2005: "protected: static class Steinberg::IUpdateHandler * Steinberg::FObject::gUpdateHandler" (?gUpdateHandler@FObject@Steinberg@@1PEAVIUpdateHandler@2@EA) already defined in juce_audio_processors.cpp.obj
C:\...\out\build\x64-Debug\juce_audio_plugin_client_VST3.cpp.obj : error LNK2005: "protected: static int Steinberg::Vst::EditController::hostKnobMode" (?hostKnobMode@EditController@Vst@Steinberg@@1HA) already defined in juce_audio_processors.cpp.obj
C:\...\out\build\x64-Debug\juce_audio_plugin_client_VST3.cpp.obj : error LNK2005: "class std::vector<class Steinberg::FObject * *,class std::allocator<class Steinberg::FObject * *> > * Steinberg::Singleton::singletonInstances" (?singletonInstances@Singleton@Steinberg@@3PEAV?$vector@PEAPEAVFObject@Steinberg@@V?$allocator@PEAPEAVFObject@Steinberg@@@std@@@std@@EA) already defined in juce_audio_processors.cpp.obj
C:\...\out\build\x64-Debug\juce_audio_plugin_client_VST3.cpp.obj : error LNK2005: "bool Steinberg::Singleton::singletonsTerminated" (?singletonsTerminated@Singleton@Steinberg@@3_NA) already defined in juce_audio_processors.cpp.obj

…and so on, with lots of other errors related to Steinberg. Happily, the project runs anyway, so I’ve been ignoring this one for years.

But I just tried updating from CMake 3.22 to 3.8, and now I get the following, more serious errors:

C:\...\out\build\x64-Debug\libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol _calloc_dbg
C:\...\out\build\x64-Debug\juce_VST3ManifestHelper.cpp.obj : error LNK2001: unresolved external symbol _calloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(_tolower.obj) : error LNK2001: unresolved external symbol _calloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol _calloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(wlocale.obj) : error LNK2001: unresolved external symbol _calloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(xwcsxfrm.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(StlCompareStringA.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(cout.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(cerr.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(StlLCMapStringA.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(wlocale.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\juce_VST3ManifestHelper.cpp.obj : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(locale0.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(filesystem.obj) : error LNK2001: unresolved external symbol _free_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(xwcsxfrm.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(StlCompareStringA.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(cout.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(cerr.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(StlLCMapStringA.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(wlocale.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\juce_VST3ManifestHelper.cpp.obj : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(locale0.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(filesystem.obj) : error LNK2001: unresolved external symbol _malloc_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(wlocale.obj) : error LNK2001: unresolved external symbol _CrtDbgReport
C:\...\out\build\x64-Debug\libcpmtd.lib(xlocale.obj) : error LNK2001: unresolved external symbol _CrtDbgReport
C:\...\out\build\x64-Debug\juce_VST3ManifestHelper.cpp.obj : error LNK2001: unresolved external symbol _CrtDbgReport
C:\...\out\build\x64-Debug\libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol _CrtDbgReport
C:\...\out\build\x64-Debug\libcpmtd.lib(cout.obj) : error LNK2001: unresolved external symbol _CrtDbgReport
C:\...\out\build\x64-Debug\libcpmtd.lib(cerr.obj) : error LNK2001: unresolved external symbol _CrtDbgReport
C:\...\out\build\x64-Debug\libcpmtd.lib(_tolower.obj) : error LNK2019: unresolved external symbol _wcsdup_dbg referenced in function _Getctype
C:\...\out\build\x64-Debug\libcpmtd.lib(xstrcoll.obj) : error LNK2001: unresolved external symbol _wcsdup_dbg
C:\...\out\build\x64-Debug\libcpmtd.lib(xmbtowc.obj) : error LNK2019: unresolved external symbol _CrtDbgReportW referenced in function _Mbrtowc
C:\...\out\build\x64-Debug\libcpmtd.lib(StlLCMapStringA.obj) : error LNK2001: unresolved external symbol _CrtDbgReportW
C:\...\out\build\x64-Debug\libcpmtd.lib(StlCompareStringA.obj) : error LNK2001: unresolved external symbol _CrtDbgReportW
C:\...\out\build\x64-Debug\libcpmtd.lib(locale.obj) : error LNK2019: unresolved external symbol _realloc_dbg referenced in function "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)
  
C:\...\out\build\x64-Debug\juce_vst3_helper.exe : fatal error LNK1120: 7 unresolved externals

This time, the project won’t run, so I’m unable to use Cmake 3.8.

Any ideas what this may be?

JUCE only supports CMake 3.22 and higher:

I’m not using anything below 3.22 atm.

AFAIK CMake 3.8 is below CMake 3.22. Do you mean CMake 3.28?

Well that’s confusing! I’ll stick with 3.22 then.