Ash Lander
Ash Lander

Reputation: 163

cmake CMAKE_C_COMPILER "is not a full path to an existing compiler tool"

This is cmake related issue Trying to build the project, and had some problems with default clang-3.5 on build machine, so installed clang-3.7 there. Unfortunately it has no clang symlink, so i am forced to find it.

Having these lines inside CMakeLists.txt file to detect clang and set it (i know this is not very good looking find code)

# Complilers, NOTE: this section should be before the Project section
find_program( CLANG_PATH clang )
find_program( CLANGCXX_PATH clang++ )
if(NOT CLANG_PATH AND NOT CLANGCXX_PATH)
    set (CLANG_SEARCH_PATH  "/usr/bin/")
    execute_process(COMMAND bash "-c" "ls ${CLANG_SEARCH_PATH} | grep -v clang++ | grep clang | head -1"
        OUTPUT_VARIABLE CLANG_FILE )
    execute_process(COMMAND bash "-c" "ls ${CLANG_SEARCH_PATH} | grep clang++ | head -1"
        OUTPUT_VARIABLE CLANGCXX_FILE )
    if(CLANG_FILE AND CLANGCXX_FILE)
        set(CLANG_PATH          "${CLANG_SEARCH_PATH}${CLANG_FILE}")
        set(CLANGCXX_PATH       "${CLANG_SEARCH_PATH}${CLANGCXX_FILE}")
        set(CMAKE_C_COMPILER    "${CLANG_PATH}")
        message(STATUS "The clang compiler discovered... ${CLANG_PATH}")
        set(CMAKE_CXX_COMPILER  "${CLANGCXX_PATH}")
        message(STATUS "The clang++ compiler discovered... ${CLANGCXX_PATH}")
    else()
        message(FATAL_ERROR "clang and clang++ were not found! Aborting...")
    endif()
endif()

Build result is (the same for clang++)

-- The clang compiler discovered... /usr/bin/clang-3.7
-- The clang++ compiler discovered... /usr/bin/clang++-3.7

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:24 (project):
  The CMAKE_C_COMPILER:

    /usr/bin/clang-3.7

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or 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.

But the path seems to be correct. If i will set it just in a dummy way instead, like

set(CMAKE_C_COMPILER    "/usr/bin/clang-3.7")
set(CMAKE_CXX_COMPILER  "/usr/bin/clang++-3.7")

it works

-- The C compiler identification is Clang 3.7.0
-- The CXX compiler identification is Clang 3.7.0
-- Check for working C compiler: /usr/bin/clang-3.7
-- Check for working C compiler: /usr/bin/clang-3.7 -- works

PS: I saw this one CMAKE_C_COMPILER is not a full path to an existing compiler tool however it was not very helpful. Left the same topic name though.

UPD:

$cmake --version
cmake version 3.6.2

Upvotes: 7

Views: 32836

Answers (2)

Harish Budereddy
Harish Budereddy

Reputation: 1

If you export compiler path you can resolve these errors. ex: export PATH=$PATH:/

Please note most of the people did a mistake at the time of compiling application. environment variables set in user mode but, while compiling applications user might keep sudo (It won't work because when the time you are passing sudo it changes user terminal to sudo user. So whichever environment variables you set in user mode it is out of scope. So if you want to compile applications in sudo then go directly to sudo mode and then export environmental variables it should work).

Upvotes: 0

Tsyvarev
Tsyvarev

Reputation: 65870

When form content of some variable according to output of execute_process, note that most of shell utilities and programs append newline to their output (this is done for pretty view in the terminal).

For remove this newline, CMake command string(STRIP) could be used.

Upvotes: 2

Related Questions