CMake:配置过程中出错,项目文件可能无效,Visual Studio 2017

sha*_*les 2 cmake visual-studio-2017

我目前正在尝试在CMake 3.10.0中编译项目,并且一直在显示上述错误框,

    The C compiler identification is unknown
    The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:2 (project):
        No CMAKE_C_COMPILER could be found.



    CMake Error at CMakeLists.txt:2 (project):
        No CMAKE_CXX_COMPILER could be found.



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

我当前正在运行Microsoft Visual Studio 15 2017,并且在配置它时使用的是x64。

小智 5

我在使用vs 2015时遇到了同样的问题,但是在安装vs 2017之后就解决了。我认为您应该修复Visual Studio 2017,然后重试。如果cmake不允许您使用“文件中的新文件”选项卡进行配置,请清除“删除缓存”,然后重试

  • 在 CMake 3.14 中,“删除缓存”位于 `File` 选项卡下 (3认同)

Chr*_*ris 4

安装Visual Studio 2017时,是否安装了Visual C++编译器?默认情况下不启用它。转到“添加或删除程序”并尝试修复/修改它以确保包含 Visual C++。


This is going to sound like a stupid suggestion but if you've just installed VS 2017, make sure you're actually able to compile a sample C++ solution. Yes, you would be surprised by the amount of people I've seen with this error that simply didn't realize their compiler wasn't installed.


My third suggestion would be to try opening the x86 or x64 Native Tools Command Prompt and try running your CMake build again. The problem, as I'm sure you've noticed haha, is that it can't find your C compilers. Running these Command Prompts will ensure your correct environment variables are set. If this fails, your C compilers are missing and you need to re-install VS2017. If this works that means there's an issue with your environment PATH.