70

I'm trying to build some code I got from GitHub using CMake, but keep getting the followings errors:

CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:/golang/project/src/github.com/devsisters/goquic/libquic/build/debug/CMakeFiles/2.8.11/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:/golang/project/src/github.com/devsisters/goquic/libquic/build/debug/CMakeFiles/2.8.11/CMakeCXXCompiler.cmake
-- Configuring incomplete, errors occurred!

How do I set these variables correctly?

I used a ./build_libs.sh file that came with the GitHub code to build this.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3871995
  • 983
  • 1
  • 10
  • 19

8 Answers8

78

The script you are executing uses the CMake Ninja generator. For that to work you need Ninja on the path. On most Linux distributions you can install it from a package.

Ubuntu: ninja-build

openSUSE: ninja

If you can't find it for your distribution, you have to download it and add its location to the path environment variable.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Marquant
  • 2,039
  • 14
  • 12
  • 2
    Thanks for your answer. I have downloaded and built ninja, plus added it to my $PATH variable and still seeing this error. I'm using redhat if that makes any difference – user3871995 Jul 29 '16 at 14:27
  • 2
    Well if it really is in you PATH you should be able to run it.Run `echo $PATH` and make sure the folder ninja is in there. – David Marquant Jul 29 '16 at 14:33
  • 2
    Maybe you have to clear your CMake cache. Just delete CMakeCache.txt in your build directory. – usr1234567 Jul 30 '16 at 05:22
  • 3
    Mac: `brew install cmake ninja` (Source: https://docs.espressif.com/projects/esp-idf/en/v3.3/get-started-cmake/macos-setup.html) – Tamás Sengel Apr 08 '22 at 15:41
11

My solution: symlink "ninja-build" to "ninja".

# ln -s /usr/bin/ninja /usr/bin/ninja-build

This only works on very old versions of CMake, which I will explain below.

I had already dropped my fresh "ninja" binary into /usr/bin and checked it had 0755 permissions. I was stumped until I ran an strace on the generator command.

# strace cmake -GNinja .. | grep -i ninja
access("ninja-build", R_OK)             = -1 ENOENT (No such file or directory)
access("/usr/local/sbin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/local/bin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/sbin/ninja-build", R_OK)       = -1 ENOENT (No such file or directory)
access("/bin/ninja-build", R_OK)        = -1 ENOENT (No such file or directory)
access("/usr/sbin/ninja-build", R_OK)   = -1 ENOENT (No such file or directory)
access("/usr/bin/ninja-build", R_OK)    = -1 ENOENT (No such file or directory)
access("/opt/texlive/2016/bin/i386-linux/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/root/bin/ninja-build", R_OK)   = -1 ENOENT (No such file or directory)

It was looking for "ninja-build", not "ninja"!

I use CMake with Ninja extensively at work and at home, on Windows and Linux. So why haven't I seen this bug before?

Well... in this instance I'm using a very old version of CMake, version 2.8.12. It's so old it's almost fossilised. So presumably it's either a CMake bug which was fixed later, or the Ninja project changed the name of the binary at some point.

  • Thanks. `# ln -s /usr/bin/ninja /usr/sbin/ninja` worked for me. – naveenKumar Jun 29 '18 at 15:24
  • Building ninja from source only creates the "ninja" binary instead of ninja-build. The error messages from CMake don't clarify this, but your answer solves it. Thanks. – Miles Mar 08 '19 at 19:31
10

In Debian/Ubuntu systems, go ahead and install it

apt install ninja-build

Then rerun CMake.

Antonio Pérez
  • 6,702
  • 4
  • 36
  • 61
PYK
  • 3,674
  • 29
  • 17
7

If ninja really exists in $PATH and it still does not work, you should check the permission of the executable file via ls -l /PATH/TO/NINJA. Make sure others have read and execute permissions (like '-rwxr-xr-x').

See also: 0013910: Ninja generator initialization fails if /usr/bin/ninja is not world-readable

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
zhangyu chen
  • 71
  • 2
  • 4
5

You may still suffer

CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

even you already have::

  • put ninja in your PATH
  • ninja executable with proper privilege
  • newer version of cmake**

Then it might because -D CMAKE_MAKE_PROGRAM and -G Ninja are specified at the same time but CMAKE_MAKE_PROGRAM with invalid value (such as empty).

For example

Android Studio with gradle plugin version :

classpath 'com.android.tools.build:gradle:7.0.0-alpha03'

and not using SDK Manager provided cmake, by:

  • put cmake executable in PATH environment variable
  • put ninja executable in PATH environment variable
  • specify cmake version equal to the one in PATH, in modules's build.gradle, like:
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.19.1" // this line
        }
    }

Then actually gradle calling cmake like this:

cmake ^
-HD:\dev\android_cv_examples\HelloNDK7\app\src\main\cpp ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON ^
-DCMAKE_SYSTEM_VERSION=26 ^
-DANDROID_ABI=arm64-v8a ^
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a ^
-DANDROID_NDK=D:\soft\Android\ndk-r21b ^
-DCMAKE_ANDROID_NDK=D:\soft\Android\ndk-r21b ^
-DCMAKE_TOOLCHAIN_FILE=D:\soft\Android\ndk-r21b\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM= ^
-DCMAKE_C_FLAGS= ^
-DCMAKE_CXX_FLAGS=-std=c++11 ^
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\dev\android_cv_examples\HelloNDK7\app\build\intermediates\cmake\debug\obj\arm64-v8a ^
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=D:\dev\android_cv_examples\HelloNDK7\app\build\intermediates\cmake\debug\obj\arm64-v8a ^
-DCMAKE_BUILD_TYPE=Debug ^
-BD:\dev\android_cv_examples\HelloNDK7\app\.cxx\cmake\debug\arm64-v8a ^
-GNinja ^
-DANDROID_PLATFORM=android-24

Note: If removing previous cmake build cache, and modify that calling script by deleting -DCMAKE_MAKE_PROGRAM then problem will be solved.

ChrisZZ
  • 1,521
  • 2
  • 17
  • 24
3

I am using Mac Monterey. I put ninja into /Applications and /Users/USER/Applications and made sure $PATH was pointing to these directories, but no luck.

I only made CMake discover Ninja by installing it via homebrew:

brew install ninja

Raildex
  • 3,406
  • 1
  • 18
  • 42
1

My issue was fixed by upgrading CMake to the latest version as specified in this answer: https://askubuntu.com/a/865294/924090

This was apparently an issue in CMake that is now fixed in the latest version. More information here: https://gitlab.kitware.com/cmake/cmake/-/issues/21486

Amin Ya
  • 1,515
  • 1
  • 19
  • 30
1

At U20 was resolved for me only when using "pip install ninja" rather than "sudo apt install ninja-build"

GM1
  • 380
  • 3
  • 14