术语“cmake”未被识别为cmdlet的名称

6
我正在尝试在Windows 10的命令行中使用CMake。以前可以使用,但我不知道为什么现在不能用了。我安装了新版本的CMake并将路径添加到环境变量中。然而,在尝试像这样在Powershell中使用它时: cmake -G "Visual Studio 14 2015 Win64" .. 它显示以下错误:
cmake : The term 'cmake' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1
这是我的环境变量:

enter image description here

我已将 C:\Program Files\CMake\bin 添加到 path 变量的末尾。我也尝试卸载和重新安装 CMake,但没有帮助。

2
在您的PowerShell会话中,路径变量中包含什么?使用$env:Path -split ';'命令查看会话中该值。 - Lee_Dailey
@Lee_Dailey 我看到了。它完全一样,只是最后一行C:\Program Files\CMake\bin不在powershell路径中。 - Hadi GhahremanNezhad
然后,您需要在 PoSh 会话启动之前添加它,或者您需要将其添加到当前 PoSh 会话中。它真的应该是您永久路径的一部分,因此我建议在启动 PowerShell 之前添加它。 - Lee_Dailey
@Lee_Dailey 我在启动 PowerShell 之前将其添加到永久路径中,但没有起作用。然而,在当前的 PowerShell 中添加它是有效的。也许我应该重新安装 PowerShell。 - Hadi GhahremanNezhad
1
重新安装 PoSh 不会改变问题。[微笑] 您可以通过使用此处显示的 dotnet 方法在您的 PoSh 会话中为该帐户进行永久更改 >>> Environment.SetEnvironmentVariable Method (System) | Microsoft Docs — https://learn.microsoft.com/en-us/dotnet/api/system.environment.setenvironmentvariable?view=netframework-4.8 <<< - Lee_Dailey
1个回答

5

在当前的PowerShell会话中,你需要将路径添加到路径环境变量中。你需要使用以下命令:

$env:path += ";C:\Program Files\cmake\bin"
cmake -g ...

谢谢,这个方法可行。但是我每次打开 PowerShell 都需要执行一遍。有没有办法将其永久添加到路径中? - Hadi GhahremanNezhad
1
是的,您必须使用此命令 cmd /c setx.exe PATH "%PATH%;C:\Program Files\Cmake\Bin" - Wasif

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接