【问题标题】:CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:20 (project)CMake 将无法正确生成此项目。调用堆栈(最近调用优先):CMakeLists.txt:20(项目)
【发布时间】:2019-08-04 16:56:09
【问题描述】:

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

cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../install ../.. 

我收到了这个错误:

-- 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):

C 编译器:

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

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

 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.

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".

谁能告诉我为什么会这样?我该如何解决这个问题?

【问题讨论】:

  • 我在使用 VS 16.6.3 的 Windows Server 2012 机器上构建时遇到了完全相同的问题。我使用 Ninja 作为生成器而不是 NMake。从您发布的日志中可以看出,CMake 无法找到 mt.exe (--mt=CMAKE_MT-NOTFOUND)。从终端运行vcvarsall.bat 后,运行where mt 仍然找不到任何东西。可能是vcvarsall.bat 脚本或VS 安装中的问题?在另一台装有 VS 16.9.5 的机器上,一切正常......

标签: windows cmake


【解决方案1】:

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

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


详细答案:

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

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

感谢this answer,我发现可以增加vcvarsall.bat 脚本的详细程度。所以我跑了

set VSCMD_DEBUG=3
vcvarsall.bat > out.txt

发现我有很多

ERROR: Registry editing has been disabled by your administrator.

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

C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86\mt.exe

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

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

【讨论】:

    【解决方案2】:

    我在 Windows 10 上使用 msys2 构建 gvsbuild 时遇到了类似的问题。

    我通过将两个文件 mt.exe 和 mt.exe.config 从“C:\Program Files (x86)\Windows Kits\8.1\bin\x86”复制到“C:\Program Files (x86)”来修复它\Microsoft Visual Studio 14.0\VC\bin" 。您可以根据您的编译器版本调整这些目录。

    这类似于Visual Studio can't build due to rc.exe

    【讨论】:

      猜你喜欢
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      相关资源
      最近更新 更多