CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found

418,692

Solution 1

Those error messages

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

or

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!

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

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.

Preconditions

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

General things you can/should try

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

  2. 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 can't find Visual Studio

  1. Try to select the correct generator version:

    > cmake --help
    > cmake -G "Visual Studio 14 2015" ..
    
  2. 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).

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_MACHINE\SOFTWARE\Microsoft\VisualStudio\[Version];InstallDir), system environment variables and - if none of the others did come up with something - plainly try to call the compiler.

CMake can't find GCC (MinGW/MSys)

  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.
    

    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.

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

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

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

Solution 2

For Ubuntu, please install the below things:

sudo apt-get update && sudo apt-get install build-essential

Solution 3

This happened to me after I installed Visual Studio 15 2017.

The C++ compiler for Visual Studio 14 2015 was not the problem. It seemed to be a problem with the Windows 10 SDK.

Adding the Windows 10 SDKs to Visual Studio 14 2015 solved the problem for me.

See attached screenshot.

Enter image description here

Solution 4

This works for me in Ubuntu 17.10 (Artful Aardvark):

apt-get update
apt-get install build-essential

Solution 5

I also experienced this error when working with CMake:

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

The 'warning' box in the MSDN library article Visual C++ in Visual Studio 2015 gave me the help that I needed.

Visual Studio 2015 doesn't come with C++ installed by default. So, creating a new C++ project will prompt you to download the necessary C++ components.

Share:
418,692
Caio Fontes
Author by

Caio Fontes

Updated on October 15, 2021

Comments

  • Caio Fontes
    Caio Fontes over 2 years

    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.
    

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

    I'm following this tutorial:

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

    • Tsyvarev
      Tsyvarev over 8 years
      You can configure project either for Visual studio with its compiler or for Makefiles with gcc. What method you have tried?
    • bames53
      bames53 over 8 years
      What is the cmake command you're entering?
    • drescherjm
      drescherjm over 8 years
      Are you using the latest CMake? What generator did you use? Did you run the commands from the Visual Studio 2015 command prompt (so it has the compiler environment variables set)?
    • Florian
      Florian over 8 years
      @bames53 Just wanted to add to corresponding command lines for @Caio Fontes to try: cmake .. -G "Visual Studio 14 2015" or cmake .. -G "MSYS Makefiles" (if gcc means MinGW). And I've seen those questions a lot (like here, here, or here) and I'm thinking we are missing a combined/tutorial answer on SO.
    • drescherjm
      drescherjm over 8 years
      I just tried this with Visual Studio 12 2013 Win64 and I had no issues at all (although I use CMake every day so I know my Vs2013 works with CMake-3.3.1). Did you erase the build folder between switching compilers?
    • Adam McKee
      Adam McKee almost 7 years
    • jrh
      jrh over 4 years
      @MarkIngram I'd say close it in the reverse direction; have the other question be a dupe of this, I think this question has better answers
  • Melaz
    Melaz over 7 years
    This worked for me. Manually creating a C++ project to install the necessary packages did the trick.
  • Natalie Cottrill
    Natalie Cottrill almost 6 years
    This solution was required at my place at work after they pushed a Windows OS update. I have used at least 2 of the solutions on this page to fix the error. The error can crop up in any number of conditions, so this is why there are several different, yet workable, answers.
  • TomTasche
    TomTasche over 5 years
    I was able to resolve the same issue by making sure the output of "xcode-select -p" points to my Xcode installation. In my case installing Xcode and running "xcode-select -r" was enough.
  • jrh
    jrh over 4 years
    Just as a heads up, some of the cmake docs links point to a really old version of CMake, remember to use the version selector to match what version you have on your computer (e.g., if you don't see a newer platform listed that you need).
  • learner
    learner over 3 years
    What to use for CentOS 7.9
  • Nick Westgate
    Nick Westgate over 3 years
    Nice list. But note that gcc can be OK while g++ is not installed, causing the error.
  • Gray Programmerz
    Gray Programmerz almost 3 years
    providing C/C++ compiler path to cmake-gui.exe solved problem.
  • Onyr
    Onyr over 2 years
    This one fixed my problem on Ubuntu 20...
  • Pablo
    Pablo over 2 years
    I did that for Ubuntu but it triggers the error "the CXX compiler identification is unknown"
  • JayCrossler
    JayCrossler about 2 years
    Thanks, spent hours trying everything else.
  • Grejo Joby
    Grejo Joby about 2 years
    You are most welcome! I also had to try a lot of things to finally come to this solution. The other solutions were too complex and was not really the issue.