Visual Studio 2017: vcvars for toolset v140

北慕城南 提交于 2020-12-29 04:11:51

问题


I installed Visual Studio 2017 and toolsets v140 and v141. To work with v140 toolset, I need to set the necessary environment via vcvars. However, running the necessary vcvars, I get various errors. I am taking vcvars from this directory - C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC - as I need to initiate the environment for the work with v140 toolset.

If I run vcvarsall, for example, then vcvarsall.bat x86 or vcvarsall.bat x86_amd64 - and I get the following error:

Error in script usage. The correct usage is:

vcvarsall.bat [option] or
vcvarsall.bat [option] store or
vcvarsall.bat [option] [version number] or
vcvarsall.bat [option] store [version number]

where [option] is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | >amd64_arm
where [version number] is either the full Windows 10 SDK version number or "8.1" to use the windows 8.1 SDK

: The store parameter sets environment variables to support store (rather than desktop) development. :

For example:

vcvarsall.bat x86_amd64
vcvarsall.bat x86_arm store
vcvarsall.bat x86_amd64 10.0.10240.0
vcvarsall.bat x86_arm store 10.0.10240.0
vcvarsall.bat x64 8.1
vcvarsall.bat x64 store 8.1 :

Please make sure either Visual Studio or C++ Build SKU is installed.

If I run a specific file vcvars, for example, vcvars32.bat, then I get another error:

ERROR: Cannot determine the location of the VS Common Tools folder.

Has anyone had the same issue, could you help? Thank you.


回答1:


I've managed to solve, so to speek, this issue using the following approach. For toolset v140 vcvars tries to obtain the required data from the registry (Visual Studio 14.0 installation directory), but, because it fails to do so, exits with an error. If you add to the Windows registry the required value, vcvars will work correctly. In case of toolset v140 installed along with Visual Studio 2017 this path for the default installation is C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\.

You need to locate the existing key where the Visual Studio 2017 installation directory is set (in my case it is HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7) and add the key with name 14.0 and value C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\




回答2:


As stated in the Microsoft forums here modifying the vcvarsall.bat script seems to solve the issue with latest VS tool installed (it did for my installation)

In case the link goes dead: the solution is to comment line 8 (or 10 depending if there are two blank lines at the beginning of the file)




回答3:


There is an additional command-line argument for the newer vcvars*.bat files: vcvars_ver.

To setup an enviroment using the VS2015 toolchain with VS2017 one has to append -vcvars_ver=14.0 to the new vcvars*.bat call.

E.g. "c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64 8.1 -vcvars_ver=14.0 sets up an environment for x64 using Windows 8.1 SDK and the MSVC2015 toolchain.

There is no need to change any value in the registry or modify the installed batch files.

Source: https://developercommunity.visualstudio.com/solutions/140023/view.html




回答4:


The problem line is

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>CALL "VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.16 10.0.18362.0

I just went to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build and found vcvars64.bat.

After studying it, I modified it like this

REM @call "%~dp0vcvarsall.bat" x64 %*
@call "%~dp0vcvarsall.bat" x64 

getting rid of the offending 14.16 10.0.18362.0 parameter. It worked. No messing up with the register.



来源:https://stackoverflow.com/questions/43939301/visual-studio-2017-vcvars-for-toolset-v140

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!