c++ - CMake 无法识别混合 C++/FORTRAN 程序中的 FORTRAN 源代码

标签 c++ cmake fortran

我正在将我的一个项目转移到 CMake(因为语法简单),我曾经使用 autotools(autoconf、automake 等)。我遇到了一个小问题,CMake 没有识别出我的源代码树中有 FORTRAN 代码。

我构建的其中一个库同时依赖于 C++ 和 FORTRAN 源代码。我使用以下语法来构建库

add_library(matrix
  double/matrix_constructor_double.cpp
  double/matrix_io_double.cpp
  double/matrix_miscmath_double.cpp
  double/matrix_miscop_double.cpp
  double/matrix_overload_double.cpp
  double/matrix_setters_double.cpp
  double/eigsrt_double.f
  double/pkconv_double.f)

CMake 运行得很好,但是当我尝试制作项目时,我得到以下信息:

Scanning dependencies of target matrix
[ 45%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_constructor_double.cpp.o
[ 50%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_io_double.cpp.o
[ 54%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_miscmath_double.cpp.o
[ 59%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_miscop_double.cpp.o
[ 63%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_overload_double.cpp.o
[ 68%] Building CXX object src/matrix/CMakeFiles/matrix.dir/double/matrix_setters_double.cpp.o

它完全忽略了我指定的 FORTRAN 代码。在 autotools 中,这不是问题。此外,CMake 也无法识别我有 FORTRAN 代码,即

-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dbwy/git_repo/chronusq/build

如果我尝试手动指定 FORTRAN 编译器,我会得到以下结果

CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_Fortran_COMPILER

我的 CMake 中是否缺少与 FORTRAN 一起使用的某些功能?我正在使用 cmake 3.0.2

最佳答案

尝试将 Fortran 指定为您的 cmake 项目的语言。默认情况下仅启用 C 和 C++:

Optionally you can specify which languages your project supports. Example languages are C, CXX (i.e. C++), Fortran, etc. By default C and CXX are enabled if no language options are given. Specify language NONE, or use the LANGUAGES keyword and list no languages, to skip enabling any languages.

http://www.cmake.org/cmake/help/v3.2/command/project.html

类似于:

project(foo C CXX Fortran)

关于c++ - CMake 无法识别混合 C++/FORTRAN 程序中的 FORTRAN 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29567547/

相关文章:

fortran - 如何消除 Fortran 文本字段开头的空格?

c++ - 为什么需要重新定义固定大小的静态数组/有效?

c++ - 添加基于模板参数的拷贝构造函数

c++ - 如何将字符串对添加到 rapidjson 文档中

c++ - 在 CMake 中静态链接时系统库的 undefined reference 错误

C - 编译器允许的语法无效?

multidimensional-array - Fortran reshape - N 维转置

c++ - 为什么在 ctor 工作中将临时变量传递给 const ref?

c++ - 在较新的 Ubuntu 版本中为旧的 Ubuntu 版本编译 C/C++

windows - 为什么在 Windows 7 64 位(使用 Eclipse/Photran/Cygwin)上使用 GDB 调试 Fortran 代码时会出现缺少 DLL 错误?