No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
我已经下载了GCC,而且我正在使用Visual Studio 2015。
我正在按照这个教程进行:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
对于Ubuntu,请安装以下内容:
sudo apt-get update && sudo apt-get install build-essential
那些错误信息
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尝试的第一件事情之一)。
查找问题的步骤取决于您想要生成的构建环境。以下教程是Stack Overflow上的答案和我在Microsoft Windows 7/8/10和Ubuntu 14.04上使用CMake的经验的集合。
前提条件
You have installed the compiler/IDE and it was able to once compile any other program (directly without CMake)
You have the latest CMake version
You have access rights on the drive you want CMake to generate your build environment
You have a clean build directory (because CMake does cache things from the last try) e.g. as sub-directory of your source tree
Windows cmd.exe
> rmdir /s /q VS2015
> mkdir VS2015
> cd VS2015
Bash shell
$ rm -rf MSYS
$ mkdir MSYS
$ cd MSYS
and make sure your command shell points to your newly created binary output directory.
你可以/应该尝试的一般方法
Is CMake able find and run with any/your default compiler? Run without giving a generator
> cmake ..
-- Building for: Visual Studio 14 2015
...
Perfect if it correctly determined the generator to use - like here Visual Studio 14 2015
What was it that actually failed?
In the previous build output directory look at CMakeFiles\CMakeError.log
for any error message that make sense to you or try to open/compile the test project generated at CMakeFiles\[Version]\CompilerIdC
|CompilerIdCXX
directly from the command line (as found in the error log).
CMake无法找到Visual Studio
Try to select the correct generator version:
> cmake --help
> cmake -G "Visual Studio 14 2015" ..
If that doesn't help, try to set the Visual Studio environment variables first (the path could vary):
> "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
> cmake ..
or use the Developer Command Prompt for VS2015
short-cut in your Windows Start Menu under All Programs
/Visual Studio 2015
/Visual Studio Tools
(thanks at @Antwane for the hint).
背景:CMake支持所有Visual Studio版本和类型(Express、Community、Professional、Premium、Test、Team、Enterprise、Ultimate等)。为了确定编译器的位置,它使用搜索注册表(例如在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\[Version];InstallDir
中)、系统环境变量以及 - 如果没有其他方法找到 - 直接尝试调用编译器的组合。
CMake无法找到GCC(MinGW/MSys)
You start the MSys bash
shell with msys.bat
and just try to directly call gcc
$ gcc
gcc.exe: fatal error: no input files
compilation terminated.
Here it did find gcc
and is complaining that I didn't gave it any parameters to work with.
So the following should work:
$ cmake -G "MSYS Makefiles" ..
-- The CXX compiler identification is GNU 4.8.1
...
$ make
If GCC was not found call export PATH=...
to add your compilers path (see How to set PATH environment variable in CMake script?) and try again.
If it's still not working, try to set the CXX
compiler path directly by exporting it (path may vary)
$ 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
For more details see How to specify new GCC path for CMake
Note: When using the "MinGW Makefiles" generator you have to use the mingw32-make
program distributed with MinGW
Still not working? That's weird. Please make sure that the compiler is there and it has executable rights (see also preconditions chapter above).
Otherwise the last resort of CMake is to not try any compiler search itself and set CMake's internal variables directly by
$ cmake -DCMAKE_C_COMPILER=/c/MinGW/bin/gcc.exe -DCMAKE_CXX_COMPILER=/c/MinGW/bin/g++.exe ..
For more details see Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++ and Cmake error setting compiler
Alternatively those variables can also be set via cmake-gui.exe
on Windows. See Cmake cannot find compiler
背景:和 Visual Studio 工具一样,CMake 支持各种不同版本的 GCC。它会在环境变量(如 CC、CXX 等)中搜索或尝试调用编译器。此外,当进行交叉编译时,CMake 也会检测到任何前缀,并将其添加到 GNU 编译器工具链的所有 binutils(包括 ar
、ranlib
、strip
、ld
、nm
、objdump
和 objcopy
)。
cmake-gui.exe
即可解决问题。 - Gray Programmerz在我的电脑上,这个方法适用于 Ubuntu 17.10 (Artful Aardvark) 版本:
apt-get update
apt-get install build-essential
当我使用CMake工作时,我也遇到过这个错误:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
在 MSDN 文库文章 Visual Studio 2015 中的 Visual C++ 中的 'warning' 盒子给了我需要的帮助。
Visual Studio 2015 默认没有安装 C++。因此,创建新的 C++ 项目将提示您下载必要的 C++ 组件。
我在使用CMake时遇到了相同的错误。在初始的CMake对话框中,我们需要选择Visual Studio编译器,但是我选择了错误的版本。
后来我将其更改为“Visual Studio 11 2012”,然后问题得到解决。(我在电脑上安装了Visual Studio Ultimate 2012版本)。一般来说,在初始的CMake配置对话框中,请尝试输入旧版本的Visual Studio。
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
C:\Users\spenc\Desktop\MyProjectDirectory
而不是C:\Users\spenc\Desktop\...\MyProjectDirectory
,此问题在Windows上就解决了。我认为问题的根源是 MSBuild 有一个文件路径长度限制 为260个字符。这导致CMake执行的基本编译器测试失败,该测试构建了一个名为CompilerIdCXX.vcxproj
的项目,并显示以下错误:C1083: Cannot open source file: 'CMakeCXXCompilerId.cpp'
,因为文件路径的长度如下所示,例如:C:\Users\spenc\Desktop\...\MyProjectDirectory\build\CMakeFiles\...\CMakeCXXCompilerId.cpp
超过了MAX_PATH限制。然后,CMake得出结论:没有CXX编译器。尝试了所有解决方案都无果后,我只需通过 cmake -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ ...
提供这些缺失的参数。
确保您选择了正确版本的Visual Studio。这比看起来更棘手,因为Visual Studio 2015实际上是Visual Studio 14,类似地,Visual Studio 2012是Visual Studio 11。我曾经错误地选择了Visual Studio 15,它实际上是Visual Studio 2017,而我安装的是2015版。
cmake .. -G "Visual Studio 14 2015"
或cmake .. -G "MSYS Makefiles"
(如果gcc
表示MinGW
)。并且我看到了很多这样的问题(如这里、这里或这里),我认为我们在SO上缺少一个结合/教程答案。 - FlorianVisual Studio 12 2013 Win64
上尝试了一下,完全没有任何问题(虽然我每天都使用 CMake,所以我知道我的 Vs2013 能够与 CMake-3.3.1 协同工作)。你在切换编译器时是否删除了构建文件夹? - drescherjm