CMakeLists.txt:30 (project) 中的 CMake 错误:找不到 CMAKE_C_COMPILER [英] CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found

查看:96
本文介绍了CMakeLists.txt:30 (project) 中的 CMake 错误:找不到 CMAKE_C_COMPILER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 CMake 制作 Visual Studio 解决方案来编译最新版本的 aseprite,而 CMake 不断给我:

I'm trying make a Visual Studio solution with CMake to compile the latest version of aseprite and CMake keeps giving me the:

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

我已经下载了 GCC,我正在使用 Visual Studio 2015.

I've already downloaded GCC, and I'm using Visual Studio 2015.

我正在学习本教程:

https://github.com/aseprite/aseprite/blob/master/安装.md

推荐答案

那些错误信息

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 在检测您的构建环境时尝试的第一件事).

just mean that CMake was unable to find your C/CXX compiler to compile a simple test program (one of the first things CMake tries while detecting your build environment).

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

The steps to find your problem are dependent on the build environment you want to generate. The following tutorials are a collection of answers here on Stack Overflow and some of my own experiences with CMake on Microsoft Windows 7/8/10 and Ubuntu 14.04.

前提

  • 您已经安装了编译器/IDE,它能够一次编译任何其他程序(直接无需 CMake)

    您有一个干净的构建目录(因为 CMake 确实缓存了上次尝试的内容)例如作为源代码树的子目录

    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.

    你可以/应该尝试的一般事情

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

    1. Is CMake able find and run with any/your default compiler? Run without giving a generator

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

    如果它正确确定要使用的生成器就完美了 - 就像这里 Visual Studio 14 2015

    Perfect if it correctly determined the generator to use - like here Visual Studio 14 2015

    实际上失败的是什么?

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

    In the previous build output directory look at CMakeFilesCMakeError.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

    1. 尽量选择正确的生成器版本:

    > cmake --help
    > cmake -G "Visual Studio 14 2015" ..
    

  • 如果这没有帮助,请先尝试设置 Visual Studio 环境变量(路径可能会有所不同):

  • 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.0VCvcvarsall.bat"
    > cmake ..
    

    或使用 Developer Command Prompt for VS2015 快捷方式,在 All Programs/Visual Studio 2015/ 下的 Windows 开始菜单中>Visual Studio 工具(感谢 @Antwane 的提示).

    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_MACHINESOFTWAREMicrosoftVisualStudio[Version];InstallDir)、系统环境变量和 - 如果没有其他确实想出了一些办法 - 显然是尝试调用编译器.

    Background: CMake does support all Visual Studio releases and flavors (Express, Community, Professional, Premium, Test, Team, Enterprise, Ultimate, etc.). To determine the location of the compiler it uses a combination of searching the registry (e.g. at HKEY_LOCAL_MACHINESOFTWAREMicrosoftVisualStudio[Version];InstallDir), system environment variables and - if none of the others did come up with something - plainly try to call the compiler.

    CMake 找不到 GCC (MinGW/MSys)

    1. 您使用 msys.bat 启动 MSys bash shell,然后尝试直接调用 gcc

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

    在这里它确实找到了 gcc 并抱怨我没有给它任何参数.

    Here it did find gcc and is complaining that I didn't gave it any parameters to work with.

    所以以下应该有效:

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

    如果未找到 GCC,请调用 export PATH=... 以添加您的编译器路径(请参阅如何在 CMake 脚本中设置 PATH 环境变量?) 然后再试一次.

    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.

    如果还是不行,尝试直接通过导出设置CXX编译器路径(路径可能会有所不同)

    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
    

    更多细节参见如何为CMake指定新的GCC路径

    注意:当使用MinGW Makefiles"生成器时,你必须使用MinGW分发的mingw32-make程序

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

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

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

    有关更多详细信息,请参阅Cmake 不尊重 -D CMAKE_CXX_COMPILER=g++Cmake 错误设置编译器

    For more details see Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++ and Cmake error setting compiler

    或者,这些变量也可以在 Windows 上通过 cmake-gui.exe 设置.请参阅Cmake 找不到编译器

    Alternatively those variables can also be set via cmake-gui.exe on Windows. See Cmake cannot find compiler

    背景:与 Visual Studio 非常相似.CMake 支持各种 GCC 风格.它搜索环境变量(CC、CXX 等)或只是尝试调用编译器.此外,它会检测任何前缀(当 交叉编译 时)并尝试将其添加到所有 binutilsGNU 编译器工具链(arranlibstripldnmobjdumpobjcopy).

    Background: Much the same as with Visual Studio. CMake supports all sorts of GCC flavors. It searches the environment variables (CC, CXX, etc.) or simply tries to call the compiler. In addition it will detect any prefixes (when cross-compiling) and tries to add it to all binutils of the GNU compiler toolchain (ar, ranlib, strip, ld, nm, objdump, and objcopy).

    这篇关于CMakeLists.txt:30 (project) 中的 CMake 错误:找不到 CMAKE_C_COMPILER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆