首页 > 解决方案 > 无法解决:“cl.exe”无法编译简单的测试程序

问题描述

我正在尝试从 ninja 构建 llvm 源代码。

我正在遵循http://clang.llvm.org/docs/LibASTMatchersTutorial.html 指南。

当我尝试在开发人员命令提示符下运行命令时 cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_BUILD_TESTS=ON

它正在抛出错误

-- The C compiler identification is MSVC 19.16.27032.1
-- The CXX compiler identification is MSVC 19.16.27032.1
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- broken
CMake Error at C:/Users/Desktop/clang-llvm/cmake/cmake-3.15.1-win64-x64/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/Desktop/clang-llvm/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/Users/Desktop/clang-llvm/ninja/ninja.exe cmTC_2dc03 && [1/2] Building C object CMakeFiles\cmTC_2dc03.dir\testCCompiler.c.obj
    [2/2] Linking C executable cmTC_2dc03.exe
    FAILED: cmTC_2dc03.exe
    cmd.exe /C "cd . && C:\Users\Desktop\clang-llvm\cmake\cmake-3.15.1-win64-x64\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_2dc03.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests  -- C:\PROGRA~2\MIB055~1\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx86\x86\link.exe /nologo CMakeFiles\cmTC_2dc03.dir\testCCompiler.c.obj  /out:cmTC_2dc03.exe /implib:cmTC_2dc03.lib /pdb:cmTC_2dc03.pdb /version:0.0  /machine:X86  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_2dc03.dir/manifest.res CMakeFiles\cmTC_2dc03.dir/manifest.rc" failed (exit code 0) with the following output:
    The system cannot find the file specified
    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:49 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/Desktop/clang-llvm/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Desktop/clang-llvm/build/CMakeFiles/CMakeError.log".


我试图运行一个程序, C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe没有错误。

请让我知道是否有解决方案?先感谢您:)

标签: cmakellvm

解决方案


我按照以下步骤操作:

1) 检查 rc.exe 所在位置并将其路径添加到环境变量PATH

就我而言,它位于此处

C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86

2) 在管理员模式下运行开发人员命令提示符。


推荐阅读