我有一个使用 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 XI 上安装了 2.8.8 版的 cmake,在 Linux 上安装了 2.8 版。