Cmake error cmake was unable to find a build program corresponding to ninja

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

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.

share:xcbuild chen-pc$ make
mkdir -p build
cmake -Bbuild -H. -G Ninja -DCMAKE_INSTALL_PREFIX=
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: /Users/chen-pc/xcbuild/build/CMakeFiles/3.2.2/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: /Users/chen-pc/xcbuild/build/CMakeFiles/3.2.2/CMakeCXXCompiler.cmake
CMake Error at CMakeLists.txt:10 (project):
No CMAKE_C_COMPILER could be found.

Tell CMake where to find the compiler by setting the CMake cache entry
CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name
if it is in the PATH.

CMake Error at CMakeLists.txt:10 (project):
No CMAKE_CXX_COMPILER could be found.

Tell CMake where to find the compiler by setting the CMake cache entry
CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler
name if it is in the PATH.

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
— Configuring incomplete, errors occurred!

Issue

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.

Solution

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.

Answered By — David Marquant

I am trying to build a project with ninja but it doesn’t work on either ubuntu 20 or 18. I tried to do it locally (18) and in Docker with 20 and 18.

Following dependencies were installed in Docker:

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget jq build-essential automake libtool pkg-config python cmake gperf git ninja-build

cmake -GNinja .. -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/linux64.cmake

Results in error (from local installed with snap other then that its consistent with fails in docker):

CMake Error at /snap/cmake/340/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:99 (message):
  Could not find toolchain file: ../cmake/platforms/linux64.cmake
Call Stack (most recent call first):
  CMakeLists.txt:9 (project)


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: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

Am I missing some important dependency? I checked that /usr/bin/ninja is readable and executable. Even set it to 777 with no effect. Error stays. I can execute ninja (which fails cause the ninja file is not generated) but its definitely available in path.

Понравилась статья? Поделить с друзьями:
  • Cmake error cmake c compiler not set after enablelanguage
  • Cmake error cannot open file for write
  • Cmake error cannot determine link language for target
  • Cmake error at cmakelists txt 2 project
  • Cmake error 127