这是与cmake相关的问题,试图构建项目,并且在构建机器上出现了默认的clang-3.5问题,因此在那里安装了clang-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:我看过这个编译器不是现有编译器工具的完整路径。,但是它没有多大帮助。但是留下了相同的主题名。
UPD:
$cmake --version
cmake version 3.6.2
发布于 2020-01-22 06:16:39
如果导出编译器路径,则可以解决这些错误。例:导出路径=$PATH:/
请注意,大多数人在编写应用程序时都犯了错误。环境变量设置在用户模式下,但是,在编译应用程序时,用户可能会保持sudo (它将无法工作,因为当您通过sudo时,它会将用户终端更改为sudo用户。因此,无论您在用户模式中设置了哪个环境变量,它都超出了作用域。因此,如果您想在sudo中编译应用程序,那么直接转到sudo模式,然后导出环境变量,它应该可以工作)。
https://stackoverflow.com/questions/46004925
复制相似问题