Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ninja not found by CMake

Tags:

cmake

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

like image 209
user3871995 Avatar asked Jul 29 '16 11:07

user3871995


3 Answers

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.

like image 108
David Marquant Avatar answered Oct 16 '22 16:10

David Marquant


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.

like image 30
Adam J Richardson Avatar answered Oct 16 '22 15:10

Adam J Richardson


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

like image 6
zhangyu chen Avatar answered Oct 16 '22 15:10

zhangyu chen