linux - cmake 在 Linux 上复制 Fortran 模块失败

标签 linux cmake fortran

我有一个使用 cmake 构建的 Fortran 代码构建。目前它可以在 Mac OS X 上运行,但是当我尝试在 Linux 上构建它时,它失败了。 Cmake 成功生成 makefile,但是当我尝试运行 makefile 时,尝试复制模块时失败。

顶级 cmake 文件是:

cmake_minimum_required (VERSION 2.8)

# Start Project and note the language used.
project (v3fit_suite Fortran)

# Set a directories to build all binary files.
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/bin)
set (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/lib)

# Fortran specific settings. The first setting tells the compiler to use the C preprocessor. The second places a common directory to place all of the module files.
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -cpp")
set (CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/modules)

# List all the subdirectories these are in library dependancy order.
add_subdirectory (LIBSTELL)
add_subdirectory (VMEC2000)
add_subdirectory (V3FITA)
add_subdirectory (MAKEGRID)
add_subdirectory (V3POST)
add_subdirectory (V3RFUN)

所有模块都应复制到 build/modules。当我在 Linux 上运行带有 VERBOSE=1 的 Makefile 时,我得到:

/usr/bin/cmake -H/home/user/reconstruction -B/home/user/reconstruction --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/user/reconstruction/CMakeFiles /home/user/reconstruction/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/user/reconstruction'
make -f LIBSTELL/CMakeFiles/stell.dir/build.make LIBSTELL/CMakeFiles/stell.dir/depend
make[2]: Entering directory `/home/user/reconstruction'
cd /home/user/reconstruction && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/user/reconstruction /home/user/reconstruction/LIBSTELL /home/user/reconstruction /home/user/reconstruction/LIBSTELL /home/user/reconstruction/LIBSTELL/CMakeFiles/stell.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/user/reconstruction'
make -f LIBSTELL/CMakeFiles/stell.dir/build.make LIBSTELL/CMakeFiles/stell.dir/requires
make[2]: Entering directory `/home/user/reconstruction'
make -f LIBSTELL/CMakeFiles/stell.dir/build.make LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o.provides.build
make[3]: Entering directory `/home/user/reconstruction'
/usr/bin/cmake -E cmake_progress_report /home/user/reconstruction/CMakeFiles 
[  0%] Building Fortran object LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o
cd /home/user/reconstruction/LIBSTELL && /usr/bin/f95  -o CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o  -cpp  -J../build/modules   -c /home/user/reconstruction/LIBSTELL/Sources/Modules/stel_kinds.f
/usr/bin/cmake -E cmake_copy_f90_mod build/modules/stel_kinds LIBSTELL/CMakeFiles/stell.dir/stel_kinds.mod.stamp GNU
Error copying Fortran module "build/modules/stel_kinds".  Tried "build/modules/STEL_KINDS.mod" and "build/modules/stel_kinds.mod".
make[3]: *** [LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o.provides.build] Error 1
make[3]: Leaving directory `/home/user/reconstruction'
make[2]: *** [LIBSTELL/CMakeFiles/stell.dir/Sources/Modules/stel_kinds.f.o.provides] Error 2
make[2]: Leaving directory `/home/user/reconstruction'
make[1]: *** [LIBSTELL/CMakeFiles/stell.dir/all] Error 2
make[1]: Leaving directory `/home/user/reconstruction'
make: *** [all] Error 2

当我使用 gfortran 而不是 f95 作为编译器时,我遇到了同样的问题。为什么这在 Mac OS X 上可以运行,但在 Linux 上却失败?在 Mac OS X 上,我安装了 2.8.8 版的 cmake,在 Linux 上,我安装了 2.8 版的 cmake。

最佳答案

事实证明,是一个看似不相关的错误导致了该问题。我有一些语句来添加一个空的包含路径。

find_library (NETCDF_F netcdff PATHS ${NETCDF_LIB_PATH})
find_file (NETCDF_I netcdf.inc ${NETCDF_INC_PATH})
if (NETCDF_C AND NETCDF_F AND NETCDF_I)
    message (STATUS "Using netcdf")
    set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -D NETCDF -I ${NETCDF_INC_PATH}")
endif ()

即使“NETCDF_INC_PATH”为空,if 语句也始终为 true。这导致编译器命令行中出现一个额外的 -I,导致一切搞砸。

关于linux - cmake 在 Linux 上复制 Fortran 模块失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11455942/

相关文章:

Javascript Date 对象返回错误的日期

linux - 在 GTK 中注入(inject)鼠标事件 (WebKitWebView)

c++ - 我的 CMakeLists 有问题吗?

fortran - Fortran 迭代求解器库

linux - 安装 salt-stack minion 失败(AWS Linux env)

cmake - 为什么我无法将 Mac 框架文件与 CMake 链接?

c++ - 如何使用 "Modern CMake"设置编译器标志?

c - 如何将动态分配的数组传递给子例程

pointers - 为什么Fortran POINTER需要一个TARGET?

linux - 指数频率轴的 FFTW