与clang和gfortran编译 [英] Compiling with clang and gfortran
问题描述
我正在尝试编译一个最近开始工作的项目,并被要求在clang而不是gcc中编译代码。这个项目有一个CMake文件,我尝试使用
cmake -DCMAKE_C_COMPILER = clang -DCMAKE_CXX_COMPILER = clang ++ ../src
然而抛出一个错误,我相信是因为clang没有Fortran编译器和该项目的一部分具有Fortran代码。有没有办法让它在编译Fortran代码时使用gfortran(以前使用gcc时使用),其余部分是使用gngrran(clang / clang ++)?
cmake文件,我认为是相关的:
enable_language(Fortran)
字符串(REGEX MATCH gfortran HAVE_GFORTRAN $ {CMAKE_Fortran_COMPILER})
字符串(REGEX MATCH xlf HAVE_XLF $ {CMAKE_Fortran_COMPILER})
字符串(REGEX MATCH pg77 HAVE_PG77 $ {CMAKE_Fortran_COMPILER})
字符串(REGEX MATCH g77 HAVE_G77 $ {CMAKE_Fortran_COMPILER} )
字符串(REGEX MATCH ifort HAVE_IFORT $ {CMAKE_Fortran_COMPILER})
字符串(REGEX MATCH f77 HAVE_F77 $ {CMAKE_Fortran_COMPILER})
如果(HAVE_GFORTRAN)
set(F_LIBRARY gfortran CACHE字符串fortran库)
find_library(F_LIBRARY NAMES gfortran)
set(FORTRAN_UNDERSCORE结束CACHE字符串fortran下划线样式的类型 - linux,end,none)
set(DEF_FORTRAN_UNDERSCORE #define FORTRAN_UNDERSCORE_END)
elseif(HAVE_X LF)
set(F_LIBRARY xlf90 CACHE字符串fortran库)
find_library(F_LIBRARY NAMES xlf90)
set(FORTRAN_UNDERSCORE none CACHE字符串)什么类型的fortran下划线样式--linux,end,none )
set(DEF_FORTRAN_UNDERSCORE#define FORTRAN_UNDERSCORE_NONE)
elseif(HAVE_PGF77)
set(F_LIBRARY pgftnrtl CACHE字符串fortran库)
find_library(F_LIBRARY NAMES pgftnrtl)
set(FORTRAN_UNDERSCORE结束CACHE字符串fortran下划线样式的类型 - linux,end,none)
set(DEF_FORTRAN_UNDERSCORE#define FORTRAN_UNDERSCORE_END)
elseif(HAVE_G77)
set F_LIBRARY g2c CACHE字符串fortran库)
find_library(F_LIBRARY NAME g2c)
set(FORTRAN_UNDERSCORE linux CACHE字符串什么类型的fortran下划线样式--linux,end,none)
set( DEF_FORTRAN_UNDERSCORE#define FORTRAN_UNDERSCORE_LINUX)
elseif(HAVE_ifort)
set(F_LIBRARY ifcore CACHE字符串fortran库)
find_library(F_LIBRARY NAM ES ifcore)
set(FORTRAN_UNDERSCORE结束CACHE字符串什么类型的fortran下划线样式--linux,end,none)
set(DEF_FORTRAN_UNDERSCORE#define FORTRAN_UNDERSCORE_END)
elseif(HAVE_F77)
set(FORTRAN_UNDERSCORE结束CACHE字符串什么类型的fortran下划线样式 - linux,end,none)
set(FORTRAN_LIBRARYCACHE stringfortran库)
set(DEF_FORTRAN_UNDERSCORE#define FORTRAN_UNDERSCORE_END)
endif()
#f77在redstorm上当前是一个例外 - 不需要它
if(NOT F_LIBRARY AND NOT HAVE_F77)
message(FATAL_ERROR 无法找到Fortran库)
endif(不是F_LIBRARY AND NOT HAVE_F77)
终端输出说:当我尝试cmake时,这是一个错误:
message(FATAL_ERROR找不到fortran库)
请让我知道是否需要发布更多信息。非常感谢!
为了不让问题开放:
如果cmake不是cmake,那么必须将变量 CMAKE_Fortran_COMPILER
设置为编译器可执行文件的名称( gfortran
)能够自动确定它。
I'm trying to compile a project I recently started working on, and was asked to compile the code in clang instead of gcc. There is a CMake file for the project, and I tried to cmake the project using
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../src
However an error is thrown, which I believe is because clang doesn't have a Fortran compiler and part of the project has Fortran code. Is there a way to make it use gfortran (previously used when gcc is used) when compiling the Fortran code, and clang/clang++ for the rest?
The part of the cmake file which I think is relevant is:
enable_language(Fortran)
string(REGEX MATCH gfortran HAVE_GFORTRAN ${CMAKE_Fortran_COMPILER})
string(REGEX MATCH xlf HAVE_XLF ${CMAKE_Fortran_COMPILER})
string(REGEX MATCH pg77 HAVE_PG77 ${CMAKE_Fortran_COMPILER})
string(REGEX MATCH g77 HAVE_G77 ${CMAKE_Fortran_COMPILER})
string(REGEX MATCH ifort HAVE_ifORT ${CMAKE_Fortran_COMPILER})
string(REGEX MATCH f77 HAVE_F77 ${CMAKE_Fortran_COMPILER})
if(HAVE_GFORTRAN)
set(F_LIBRARY gfortran CACHE string "fortran library")
find_library(F_LIBRARY NAMES gfortran)
set(FORTRAN_UNDERSCORE end CACHE string "What type of fortran underscore style - linux,end,none")
set(DEF_FORTRAN_UNDERSCORE "#define FORTRAN_UNDERSCORE_END")
elseif(HAVE_XLF)
set(F_LIBRARY xlf90 CACHE string "fortran library")
find_library(F_LIBRARY NAMES xlf90)
set(FORTRAN_UNDERSCORE none CACHE string "What type of fortran underscore style - linux,end,none")
set(DEF_FORTRAN_UNDERSCORE "#define FORTRAN_UNDERSCORE_NONE")
elseif(HAVE_PGF77)
set(F_LIBRARY pgftnrtl CACHE string "fortran library")
find_library(F_LIBRARY NAMES pgftnrtl)
set(FORTRAN_UNDERSCORE end CACHE string "What type of fortran underscore style - linux,end,none")
set(DEF_FORTRAN_UNDERSCORE "#define FORTRAN_UNDERSCORE_END")
elseif(HAVE_G77)
set(F_LIBRARY g2c CACHE string "fortran library")
find_library(F_LIBRARY NAMES g2c)
set(FORTRAN_UNDERSCORE linux CACHE string "What type of fortran underscore style - linux,end,none")
set(DEF_FORTRAN_UNDERSCORE "#define FORTRAN_UNDERSCORE_LINUX")
elseif(HAVE_ifort)
set(F_LIBRARY ifcore CACHE string "fortran library")
find_library(F_LIBRARY NAMES ifcore)
set(FORTRAN_UNDERSCORE end CACHE string "What type of fortran underscore style - linux,end,none")
set(DEF_FORTRAN_UNDERSCORE "#define FORTRAN_UNDERSCORE_END")
elseif(HAVE_F77)
set(FORTRAN_UNDERSCORE end CACHE string "What type of fortran underscore style - linux,end,none")
set(FORTRAN_LIBRARY "" CACHE string "fortran library")
set(DEF_FORTRAN_UNDERSCORE "#define FORTRAN_UNDERSCORE_END")
endif()
# f77 on redstorm currently an exception - doesn't need it
if(NOT F_LIBRARY AND NOT HAVE_F77)
message(FATAL_ERROR "Cannot find fortran library")
endif(NOT F_LIBRARY AND NOT HAVE_F77)
Terminal output says that this is threw an error when I tried cmake:
message(FATAL_ERROR "Cannot find fortran library")
Please let me know if I need to post any more info. Many thanks in advance!
In order not to leave the question open:
The variable CMAKE_Fortran_COMPILER
must be set to the name of the compiler executable (gfortran
) if cmake is not able to determine it automatically.
这篇关于与clang和gfortran编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!