Adam Stafiej
Adam Stafiej

Reputation: 103

How can I change MSVC compiler version in a CMAKE project?

Since microsoft broke the compiler (again) in version 14.29.30037 (reported as 19.29.30038.1 by CMAKE for some reason) (look here) I need to go back to 14.28.something. I already downloaded 14.28.29910 through Visual Studio Installer and my Microsoft Visual Studio\2019\Community\VC\Tools\MSVC folder now contains folders with both versions.

However I can't find a way to force CMAKE to use this particular older version. I use CLion CMAKE integration and my settings look like this. toolchain settingscmake settings

Please note that I've already tried setting Make, C Compiler and C++ Compiler paths to their counterparts in older compiler. This results in CMAKE reporting the desired 19.28.29915.0 compiler version (love the number of different versioning conventions microsoft uses by the way). Despite that, when I try to build the project I get the following:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\yvals_core.h(541): fatal error C1189: #error:  STL1001: Unexpected compiler version, expected MSVC 19.29 or newer.
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\HostX86\x64\cl.exe' : return code '0x2'
Stop.

I guess this implies that not all parts of the compiler (some includes in this case) were switched to the old version.

If for some reason any piece of my code would help you with answering this question, the repo is available here

Please also note that despite how much I'd love to simply switch to GCC, I cannot because of CUDA support on Windows. I also cannot use different (older) Visual Studio version as the project requires C++ 20. Also, bonus question: How is it possible for a company as relevant as microsoft to literally break an enterprise-class development tool?

Upvotes: 1

Views: 5494

Answers (1)

Pavel Kisialiou
Pavel Kisialiou

Reputation: 51

The following solution helped me:

  1. Find vcvarsall.bat in the directory with your Visual Studio installation. (I have Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat)
  2. Run vcvarsall.bat <your_arch> -vcvars_ver=<msvc_version>. In your case, put -vcvars_ver=14.28. Example of <your_arch> is amd64. This will set all the environment variables for desired MSVC version.
  3. Start CLion from the command line with the created environment.

Upvotes: 3

Related Questions