我在Fortran中有一个拆分项目,子目录作为库:
# ./CMakeLists.txt
cmake_minimum_required (VERSION 2.8)
project (Simulation Fortran)
enable_language(Fortran)
add_subdirectory(lib)
add_executable(Simulation main.f90)
include_directories(lib)
add_dependencies(Simulation physicalConstants)
target_link_libraries(Simulation physicalConstants)
根目录只包含一个Fortran源代码文件:
! ./main.f90:
program simulation
use physicalConstants
implicit none
write(*,*) "Boltzmann constant:", k_b
end program simulation
我的子目录lib
包含另一个CMakeLists.txt
以及Fortran模块源文件:
# ./lib/CMakeLists.txt:
cmake_minimum_required (VERSION 2.8)
enable_language(Fortran)
project(physicalConstants)
add_library( physicalConstants SHARED physicalConstants.f90)
! ./lib/physicalConstants.f90:
module physicalConstants
implicit none
save
real, parameter :: k_B = 1.38e-23
end module physicalConstants
我尝试使用cmake构建那些。 Make会在physicalconstants.mod
目录中生成lib
,但在main.f90.o
的构建过程中找不到此文件:
Fatal Error: Can't open module file 'physicalconstants.mod' for reading at (1): No such file or directory
我在这里缺少什么?