这个问题在这里已有答案:
当我加载开发人员工具时:
********************************************************************** ** Visual Studio 2017 Developer Command Prompt v15.9.7 ** Copyright (c) 2017 Microsoft Corporation ********************************************************************** [vcvarsall.bat] Environment initialized for: 'x64'
我尝试通过以下方式为CMD中的C ++ hello world应用程序生成构建文件:
cmake -G 'NMake Makefiles'
我明白了:
CMake Error: Could not create named generator 'NMake Generators Visual Studio 16 2019 = Generates Visual Studio 2019 project files. Use -A option to specify architecture. * Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files. Optional [arch] can be "Win64" or "IA64". Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files. Optional [arch] can be "Win64" or "IA64". Borland Makefiles = Generates Borland makefiles. NMake Makefiles = Generates NMake makefiles. NMake Makefiles JOM = Generates JOM makefiles. Green Hills MULTI = Generates Green Hills MULTI files (experimental, work-in-progress). MSYS Makefiles = Generates MSYS makefiles. MinGW Makefiles = Generates a make file for use with mingw32-make. # etc.
但是如果我通过在CMD中编写powershell
来切换到PowerShell并运行相同的命令:
cmake -G 'NMake Makefiles'
它工作正常:
-- The C compiler identification is MSVC 19.16.27027.1 -- The CXX compiler identification is MSVC 19.16.27027.1 # etc.
知道为什么cmake
在PowerShell中工作而在CMD中工作吗?
Windows命令提示符不会将单引号识别为引用字符。您必须使用双引号。
更改
cmake -G 'NMake Makefiles'
至
cmake -G "NMake Makefiles"
问题就会消失。