铿锵和gfortran编译(Compiling with clang and gfortran)

2019-10-20 19:08发布

我试图编译一个项目,我最近开始工作,并要求编译代码的铿锵而不是GCC。 目前该项目的CMake的文件中,我尝试使用到C进行项目

cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../src

然而抛出一个错误,我相信这是因为铛没有一个Fortran编译和项目的一部分,具有Fortran代码。 有没有一种方法,使之使用gfortran编译Fortran代码时(使用GCC时之前使用),和铛/铛++的休息吗?

CMake的文件我认为部分相关的是:

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)

终端输出说,当我试图cmake的,这是抛出一个错误:

message(FATAL_ERROR "Cannot find fortran library")

请让我知道,如果我需要张贴任何更多的信息。 提前谢谢了!

Answer 1:

为了不离开的问题打开:

变量CMAKE_Fortran_COMPILER必须设置为编译器可执行文件(名称gfortran如果CMake的不能自动确定)。



文章来源: Compiling with clang and gfortran