【发布时间】:2019-10-07 08:51:40
【问题描述】:
我想在cmake中自动设置编译路径(例如:icc),这样我的程序只要安装了icc就可以在任何计算机上编译,我们不需要关心@在哪里987654324@已安装。
首先,我使用以下命令来设置编译器。一切正常。
set(Intel_C_COMPILER "/opt/intel/compilers_and_libraries_2019.0.117/linux/bin/intel64/icc")
set(Intel_CXX_COMPILER "/opt/intel/compilers_and_libraries_2019.0.117/linux/bin/intel64/icpc")
set(CMAKE_C_COMPILER ${Intel_C_COMPILER} )
set(CMAKE_CXX_COMPILER ${Intel_CXX_COMPILER})
project(MyProject)
....
然后,我想自动设置编译器路径,我知道下面的命令可以找到编译器路径
which icc
所以我写了以下命令尝试通过cmake自动设置编译器。
execute_process(COMMAND which icc OUTPUT_VARIABLE Intel_C_COMPILER)
execute_process(COMMAND which icpc OUTPUT_VARIABLE Intel_CXX_COMPILER)
message(Intel_CXX_COMPILER: ${Intel_C_COMPILER})
message(Intel_CXX_COMPILER: ${Intel_CXX_COMPILER})
set(CMAKE_C_COMPILER ${Intel_C_COMPILER} )
set(CMAKE_CXX_COMPILER ${Intel_CXX_COMPILER})
project(MyProject)
....
在这种情况下,发生了一些奇怪的事情,cmake 显示:
Intel_CXX_COMPILER:/opt/intel/compilers_and_libraries_2019.0.117/linux/bin/intel64/icpc
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:27 (project): The CMAKE_C_COMPILER:
/opt/intel/compilers_and_libraries_2019.0.117/linux/bin/intel64/icc
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.
CMake Error at CMakeLists.txt:27 (project): The CMAKE_CXX_COMPILER:
/opt/intel/compilers_and_libraries_2019.0.117/linux/bin/intel64/icpc
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the
environment variable "CXX" or 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.
-- Configuring incomplete, errors occurred!
CMake表示该路径不是现有编译器的完整路径,但如message所示,正是编译器所在的位置!
我知道我们可以设置编译器的其他技术,例如导出一些环境变量以帮助 cmake 找到路径,但我想知道为什么我的方法不起作用?
有没有更好的方法可以解决这个问题?
提前致谢。
【问题讨论】:
-
在您的
Intel_C_COMPILER和Intel_CXX_COMPILER中有traling 换行符:它是which <...>命令输出的一部分,并被execute_process抓取。要删除该换行符,请参阅该问题:stackoverflow.com/questions/39496043/…。顺便说一句,您是否将 CMake 日志正确格式化为 代码,您(和我们)很容易在您的路径中找到超出的换行符。这就是为什么日志应该避免格式化为 blockquote。 -
@Tsyvarev 你直接暗示了这一点!非常感谢!我现在已将 CMake 日志编辑为代码。顺便说一句,您想复制您的评论作为答案吗?我想选择你的答案作为接受。
标签: cmake