CMake 将无法正确生成此项目。调用堆栈(首先是最近的调用):CMakeLists.txt:20(项目)

Shu*_*ari 5 windows cmake

我想在运行以下命令时在 Windows 系统中安装协议缓冲区:

cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../install ../.. 
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

-- The C compiler identification is MSVC 19.22.27905.0
-- The CXX compiler identification is MSVC 19.22.27905.0

-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.22.27905/bin/Hostx64/x64/cl.exe

-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.22.27905/bin/Hostx64/x64/cl.exe -- broken

CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
Run Code Online (Sandbox Code Playgroud)

C 编译器:

    "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.22.27905/bin/Hostx64/x64/cl.exe"
Run Code Online (Sandbox Code Playgroud)

无法编译简单的测试程序。它失败并显示以下输出:

 Change Dir: C:/ProtoBuff/protobuf-3.9.0/cmake/build/release/CMakeFiles/CMakeTmp

Run Build Command(s):nmake /nologo cmTC_5d4c2\fast &&       "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX64\x64\nmake.exe" -f CMakeFiles\cmTC_5d4c2.dir\build.make /nologo -L                  CMakeFiles\cmTC_5d4c2.dir\build
Building C object CMakeFiles/cmTC_5d4c2.dir/testCCompiler.c.obj
    C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1422~1.279\bin\Hostx64\x64\cl.exe @C:\Users\shubh\AppData\Local\Temp\nm4F4E.tmp
testCCompiler.c
Linking C executable cmTC_5d4c2.exe
    "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_5d4c2.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests  -- C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1422~1.279\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_5d4c2.dir\objects1.rsp @C:\Users\shubh\AppData\Local\Temp\nm50F5.tmp
RC Pass 1: command "rc /fo CMakeFiles\cmTC_5d4c2.dir/manifest.res CMakeFiles\cmTC_5d4c2.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the file specifiedNMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
Run Code Online (Sandbox Code Playgroud)

CMake 将无法正确生成此项目。调用堆栈(首先是最近的调用):

CMakeLists.txt:20 (project)

-- Configuring incomplete, errors occurred!
See also "C:/ProtoBuff/protobuf-3.9.0/cmake/build/release/CMakeFiles/CMakeOutput.log".
See also "C:/ProtoBuff/protobuf-3.9.0/cmake/build/release/CMakeFiles/CMakeError.log".
Run Code Online (Sandbox Code Playgroud)

有人能告诉我为什么会这样吗?我该如何解决?

Rac*_*box 0

我在使用 VS 16.6.3 通过自动 TFS 构建代理在 Windows Server 2012 计算机上构建时遇到了完全相同的问题。我使用 Ninja 作为生成器而不是 NMake。

TL;DR:检查执行构建的用户帐户是否具有查询 Windows 注册表的权限。


详细答案:

从您发布的日志中,我可以发现 CMake 无法找到mt.exe(检查--mt=CMAKE_MT-NOTFOUND传递给链接器的选项)。我遇到了同样的问题:CMake 找不到mt.exe.

您准备如何准备命令行?我想你正在像我一样跑步vcvarsall.bat(或同等水平)。如果我打开命令行,运行vcvarsall.bat脚本然后运行where mt​​,我不会得到任何结果。这意味着该脚本无法正确设置环境,并最终导致 CMake 因该错误而失败。

感谢这个答案,我发现可以增加vcvarsall.bat脚本的冗长性。所以我跑

set VSCMD_DEBUG=3
vcvarsall.bat > out.txt
Run Code Online (Sandbox Code Playgroud)

发现我有很多

ERROR: Registry editing has been disabled by your administrator.
Run Code Online (Sandbox Code Playgroud)

深入研究及其嵌套脚本,我在与 Windows 10 SDK 检测相关的部分中vcvarsall.bat发现了许多调用。reg query <key>在另一台正常运行的机器上,mt.exe位于

C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86\mt.exe
Run Code Online (Sandbox Code Playgroud)

reg query <key>如果我通过从干净的命令行运行相同的命令(使用运行构建的同一用户)进行双重检查,我会得到相同的vcvarsall.bat脚本错误。

通过向运行构建的用户添加适当的权限,我设法解决了这个问题。