cmake CMAKE_C_COMPILER“不是现有编译器工具的完整路径”

2024-01-14

This is cmake相关问题 尝试构建项目,但在默认情况下遇到了一些问题铿锵-3.5在构建机器上,所以安装铿锵-3.7那里。不幸的是它没有clang符号链接,所以我被迫找到它。

里面有这些线CMakeLists.txt文件来检测 clang 并设置它(我知道这不是很好看的查找代码)

# 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()

构建结果是(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.

但这条路似乎是正确的。 如果我只是以一种虚拟的方式设置它,就像

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

有用

-- 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:我看过这个CMAKE_C_COMPILER 不是现有编译器工具的完整路径 https://stackoverflow.com/questions/45140273/cmake-c-compiler-is-not-a-full-path-to-an-existing-compiler-tool但这并没有多大帮助。但留下了相同的主题名称。

UPD:

$cmake --version
cmake version 3.6.2

当根据输出形成某个变量的内容时execute_process,请注意,大多数 shell 实用程序和程序追加换行符到他们的输出(这样做是为了在终端中获得漂亮的视图)。

要删除此换行符,CMake 命令字符串(条带) https://cmake.org/cmake/help/v3.9/command/string.html#id18可用于。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

cmake CMAKE_C_COMPILER“不是现有编译器工具的完整路径” 的相关文章

随机推荐