2015-09-26 247 views
49

我试图做的CMake与Visual Studio解决方案来编译最新版本aseprite和cmake的一直给我的:CMake的错误在的CMakeLists.txt:30(项目):无CMAKE_C_COMPILER可以发现

No CMAKE_C_COMPILER could be found. 
No CMAKE_CXX_COMPILER could be found. 

我已经下载了gcc和我使用的Visual Studio 2015年

我下面这个教程/

https://github.com/aseprite/aseprite/blob/master/INSTALL.md

我一直在寻找大约3个小时,并没有在互联网上的解决方案。

+0

您可以使用其编译器为Visual Studio配置项目,或使用gcc为Makefiles配置项目。你尝试过什么方法? – Tsyvarev

+0

你输入的cmake命令是什么? – bames53

+0

你使用最新的CMake吗?你使用了什么发电机?你是否从Visual Studio 2015命令提示符运行命令(因此它具有编译器环境变量集)? – drescherjm

回答

62

这些错误消息

CMake Error at ... (project): 
    No CMAKE_C_COMPILER could be found. 
-- Configuring incomplete, errors occurred! 
See also ".../CMakeFiles/CMakeOutput.log". 
See also ".../CMakeFiles/CMakeError.log". 

CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. 
Please set CMAKE_CXX_COMPILER to a valid compiler path or name. 
... 
-- Configuring incomplete, errors occurred! 

只是意味着CMake的是无法找到你的C/CXX编译器编译一个简单的测试程序(的第一件事情之一CMake的尝试,而检测你的构建环境)。

找到问题的步骤取决于您想要生成的构建环境。以下教程是关于StackOverflow的一系列答案,以及我在MS Windows 7/8/10和Ubuntu 14.04上使用CMake的一些经验。

前提

  • 您已安装了编译器/ IDE,它是能够一次编译任何其它程序(没有直接的CMake)
  • 描述您有最新的CMake version
  • 你有你想要的CMake生成构建环境的驱动器上的访问权限
  • 你有一个干净的生成目录(因为CMake会缓存最后一次尝试的东西)eg作为你的源代码树

    的Windows CMD.EXE的子目录

    > rmdir /s /q VS2015 
    > mkdir VS2015 
    > cd VS2015 
    

    的Bash shell

    $ rm -rf MSYS 
    $ mkdir MSYS 
    $ cd MSYS 
    

    ,并确保您的命令shell点到新创建的二进制输出目录。

一般的东西,你可以/应该尝试

  1. CMake的是能够找到并运行任何/默认的编译器?不给发电机

    > cmake .. 
    -- Building for: Visual Studio 14 2015 
    ... 
    

    完美的,如果它正确地确定使用发电机运行 - 喜欢这里Visual Studio 14 2015

  2. 那是什么,实际上失败了吗?

    在之前的编译输出目录中,查看CMakeFiles\CMakeError.log,了解对您有意义的任何错误消息,或者尝试打开/编译在CMakeFiles\[Version]\CompilerIdC处生成的测试项目| CompilerIdCXX直接从命令行(在错误日志中找到)。

CMake的不能找到的Visual Studio

  1. 尽量选择正确的generator version

    > cmake --help 
    > cmake -G "Visual Studio 14 2015" .. 
    
  2. 如果不帮尝试设置VS环境变量第一个(路径可能不同)

    > "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" 
    > cmake .. 
    

    或使用Developer Command Prompt for VS2015快捷在Windows开始菜单下All Programs/Visual Studio 2015/Visual Studio Tools(感谢在@Antwane的提示)

背景:CMake的不支持所有Visual Studio版本和口味(Express,Community,Professional,Premium,Test,Team,Enterprise,Ultimate,...)。为了确定编译器的位置,它使用搜索注册表的组合(例如,在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[Version];InstallDir),系统环境变量和 - 如果其他人都没有提出任何问题 - 明显地尝试调用编译器。

CMake的不能找到GCC(MinGW的/ MSys的)

  1. 您与msys.bat启动MSys的bash壳,只是尝试直接调用gcc

    $ gcc 
    gcc.exe: fatal error: no input files 
    compilation terminated. 
    

    这确实发现gcc,并抱怨说我没有给它任何参数。

    所以下面应该工作:

    $ cmake -G "MSYS Makefiles" .. 
    -- The CXX compiler identification is GNU 4.8.1   
    ... 
    $ make 
    

    如果GCC没有找到电话export PATH=...添加你的编译路径(见How to set PATH environment variable in CMake script?),然后再试一次。

  2. 如果它仍然没有工作,试图直接通过导出其设置的CXX编译器的路径(路径可能会有所不同)

    $ export CC=/c/MinGW/bin/gcc.exe 
    $ export CXX=/c/MinGW/bin/g++.exe 
    $ cmake -G "MinGW Makefiles" .. 
    -- The CXX compiler identification is GNU 4.8.1   
    ... 
    $ mingw32-make 
    

    欲了解更多详情,请参阅how to specify new gcc path for cmake

    注意:当使用“MinGW Makefiles”发电机,你必须使用mingw32-make程序与MinGW分销

  3. 仍然无法正常工作?这很奇怪。请确保编译器在那里,它具有可执行权限(另请参阅上述前提条件)。

    否则cmake的最后一招就是不要尝试任何编译器搜索本身并直接设置的CMake的内部变量通过

    $ cmake -DCMAKE_C_COMPILER=/c/MinGW/bin/gcc.exe -DCMAKE_CXX_COMPILER=/c/MinGW/bin/g++.exe .. 
    

    欲了解更多详情,请参见Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++Cmake error setting compiler

    或者这些变量也可以设置通过Windows上的cmake-gui.exe。见Cmake cannot find compiler

背景:大致相同与Visual Studio。 CMake支持各种GCC风格。它搜索环境变量(CC,CXX,...)或简单地尝试调用编译器。此外,它会检测到任何前缀(当cross-compiling),并试图将其添加到GNU编译器工具链(arranlibstripldnmobjdumpobjcopy)的所有的binutils。

3

我和CMake有同样的错误。就我而言,我在初始CMake对话框中使用了错误的visual studio版本,我们必须选择visual studio编译器。然后我将它改为“Visual Studio 11 2012”,并且工作正常。 (我的电脑上有Visual Studio Ultimate 2012版本)。一般来说,尝试在初始CMake配置对话框中给出较旧版本的Visual Studio版本。

4

我在构建libgit2-0.23.4时遇到了这个问题。对我来说,问题是C++编译器&相关软件包未与VS2015一起安装,因此“C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ VC \ vcvarsall.bat”文件丢失,Cmake无法使用找到编译器。

我在Visual Studio 2015年GUI尝试手动创建一个C++项目(C:\ Program Files文件(x86)的\微软的Visual Studio 14.0 \ Common7 \ IDE \ devenv.exe的) 以及在创建项目时,我有提示下载C++ &相关软件包。

下载需要的软件包后,我可以看到vcvarsall。蝙蝠& CMake的是能够找到下面的日志中成功执行的编译器&:

C:\Users\aksmahaj\Documents\MyLab\fritzing\libgit2\build64>cmake .. 
-- Building for: Visual Studio 14 2015 
-- The C compiler identification is MSVC 19.0.24210.0 
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual   
Studio 14.0/VC/bin/cl.exe 
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual 
Studio 14.0/VC/bin/cl.exe -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR) 
-- zlib was not found; using bundled 3rd-party sources. 
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of 
the default search path. 
-- Looking for futimens 
-- Looking for futimens - not found 
-- Looking for qsort_r 
-- Looking for qsort_r - not found 
-- Looking for qsort_s 
-- Looking for qsort_s - found 
-- Looking for clock_gettime in rt 
-- Looking for clock_gettime in rt - not found 
-- Found PythonInterp: C:/csvn/Python25/python.exe (found version "2.7.1") 
-- Configuring done 
-- Generating done 
-- Build files have been written to:  
C:/Users/aksmahaj/Documents/MyLab/fritzing/libgit2/build64 
+1

这对我有用。手动创建一个C++项目来安装必要的软件包也有诀窍。 – Melaz

9

通过CMake

No CMAKE_C_COMPILER could be found. 
No CMAKE_CXX_COMPILER could be found. 

此MSDN库文章https://msdn.microsoft.com/en-us/library/60k1461a.aspx中的“警告”框工作时,我也遇到过这个错误给了我需要的帮助。

Visual Studio 2015没有默认安装C++。所以,创建一个新的C++项目会提示你下载必要的C++组件。

2

确保您选择了正确版本的Visual Studio。这比看起来更复杂,因为Visual Studio 2015实际上是Visual Studio 14,而Visual Studio 2012也是Visual Studio 11.我错误地选择了Visual Studio 15,实际上是Visual Studio 2017,当我安装了2015时。

0

我更新的Visual Studio 2015年更新2到Visual Studio 2015年更新3,它解决了我的问题。

1

的Ubuntu请安装下面的事情:

sudo易于得到更新& &命令和apt-get安装建立必要的

3

这happend给我后,我安装了Visual Studio 2017年15

Visual Studio 14 2015的C++编译器不是问题。这似乎是Windows 10 sdk的问题。

将Windows10 sdk添加到Visual Studio 14 2015为我解决了这个问题。

查看附件截图。

enter image description here

0

我与CMake的图形用户界面(No CMAKE_CXX_COMPILER could be found.)相同的问题,而在命令行中运行cmake的正常工作。后手动添加条目

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin

它为我工作。