GFortran和CodeBlocks问题与模块和多个文件 [英] GFortran and CodeBlocks issue with Modules and Multiple Files
问题描述
我正在使用GFortran和CodeBlocks,但我遇到了有关模块和多个文件的问题。
i不断收到此错误:
致命错误:无法打开模块文件'mesh.mod' (1):没有这样的文件或目录
由于某些原因,GFortran没有构建网格。 mod'文件。
当我将所有代码放在一个.f90文件中时,不会发生这个问题。
$ b Bellow是发生此错误的代码示例。 p>
main.f90
单元网格
隐式无
INTEGER :: IMAX,JMAX,NMAX
REAL(8),ALLOCATABLE :: XD(:),YD(:),FX(:,:),FY(:, :)
REAL (8):: PI,E,DX,DY,H,L,RHO,MU
PARAMETER(PI = ACOS(-1.D0))
参数(E = 2.718)
END MODULE MESH
!****************************************** ********************
程序Cavity
使用网格
隐式无
实数(8) ,Allocatable :: func(:)
Real(8):: Der,DfDx
integer :: i
$ b IMAX = 10
DX = 1. / 10
分配(xd(IMAX),func(IMAX))
Do i = 1,IMAX
xd(i)= i * DX
End Do
Do i = 1,IMAX
func(i)= xd(i)** 2
End Do
Der = Dfdx( func,2)
写(*,*)Der
结束程序Cavity
Derivatives.f90
真实( 8)函数DfDx(f,i)
使用网格
隐式无
Real(8):: f(1:Imax)
integer :: i
DfDx =(f(i + 1)-f(i-1))/(2d0 * dx)
返回
结束函数DfDx
当我使用控制台命令行编译代替CodeBlocks接口时,我已经解决了这个问题(用模块编译多个文件),但我仍然遇到CodeBlocks的这个问题。
<有没有人知道如何解决这个问题?解决方案
问题是CodeBlocks中的项目是内置的出现的顺序,从上到下( CodeBlocks Wiki ),换句话说,这些文件是按字母顺序编译的。
这意味着在我的情况下,Derivatives.f90被编译之前比Main.f90导致错误。
解决此问题的一种方法是设置 在 I am working with GFortran and CodeBlocks but I'm having an issue about Modules and Multiple files.
i keep getting this error: For some reason, GFortran is not building the 'mesh.mod' file.
This problem does not occur when I put all the code in a single .f90 file. Bellow is an example of code that this error happens. main.f90 Derivatives.f90 When I use console command line compilation instead of CodeBlocks interface I already solved this problem (Compiling Multiple Files with modules) but I'm still getting this problem with CodeBlocks. Does anyone know how to solve this issue? The problem is that in CodeBlocks "projects are built in the order of appearence, from top to bottom" (CodeBlocks Wiki), in other words, the files are compiled alphabetically.
Which means that in my case, Derivatives.f90 was being compiled before than Main.f90 causing the error. A way to circumvent the problem is to set only the And use the command 这篇关于GFortran和CodeBlocks问题与模块和多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $
Main.f90
b 项目/属性...
构建目标文件
在选项卡构建目标
仅检查 Main.f90
Main中使用命令
代码以正确的顺序包含其他包含'File_Name.f90'
.f90 f90
文件进行编译。Fatal Error: Can't open module file 'mesh.mod' for reading at (1): No such file or directory
MODULE MESH
IMPLICIT NONE
INTEGER :: IMAX,JMAX,NMAX
REAL(8), ALLOCATABLE :: XD(:),YD(:),FX(:,:),FY(:,:)
REAL(8) :: PI,E,DX,DY,H,L,RHO,MU
PARAMETER (PI = ACOS(-1.D0))
PARAMETER (E = 2.718)
END MODULE MESH
!**************************************************************
program Cavity
Use Mesh
implicit none
Real(8), Allocatable :: func(:)
Real(8) :: Der,DfDx
integer :: i
IMAX=10
DX=1./10
Allocate(xd(IMAX),func(IMAX))
Do i=1,IMAX
xd(i)=i*DX
End Do
Do i=1,IMAX
func(i) = xd(i)**2
End Do
Der=Dfdx(func,2)
Write(*,*) Der
End program Cavity
Real(8) Function DfDx(f,i)
Use Mesh
implicit none
Real(8) :: f(1:Imax)
integer :: i
DfDx=(f(i+1)-f(i-1))/(2d0*dx)
return
end function DfDx
Main.f90
file as build target in CodeBlocks:
Project/Properties...
Build Target Files
at the tab Build targets
check only Main.f90
Include 'File_Name.f90'
inside the Main.f90
code to include the other f90
files for compilation in the right order.