【问题标题】:Compiling with clang and gfortran使用 clang 和 gfortran 编译
【发布时间】:2014-08-25 19:32:10
【问题描述】:

我正在尝试编译我最近开始工作的项目,并被要求在 clang 而不是 gcc 中编译代码。该项目有一个CMake文件,我尝试使用

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

但是抛出了一个错误,我认为这是因为 clang 没有 Fortran 编译器,并且项目的一部分有 Fortran 代码。有没有办法让它在编译 Fortran 代码时使用 gfortran(以前使用 gcc 时使用),其余部分使用 clang/clang++?

我认为相关的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")

如果我需要发布更多信息,请告诉我。非常感谢!

【问题讨论】:

  • 您是否尝试将CMAKE_Fortran_COMPILER 设置为任何内容,比如gfortran
  • 这似乎成功了,谢谢!现在 cmake 可以正常工作,运行 make 时出现一些编译错误,但不确定这是否是编码问题,所以是时候研究一下了...

标签: c++ cmake fortran clang gfortran


【解决方案1】:

为了不让问题悬而未决:

如果 cmake 无法自动确定变量CMAKE_Fortran_COMPILER,则必须将其设置为编译器可执行文件的名称 (gfortran)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    相关资源
    最近更新 更多