bash: cannot execute binary file exec format 错误 fortran
bash: cannot execute binary file exec format error fortran
当我运行下面给出的代码时,它总是给我以下错误:
bash: cannot execute binary file exec format error fortran
此外,文件 "file" 并未在代码中提到的位置创建。我有一个 64 位处理器和 64 位版本的 Ubuntu 16.04,所以这似乎不是问题所在。谁能指出我错在哪里?
program sandpile_model
implicit none
integer, parameter :: len = 20
integer, dimension(len,len) :: square
!real, dimension(len,len) :: blah
!open(unit=1,file="\home\sandpile\fortran\file")
!dummy variables
integer :: i,j,d
do i=1,len
do j=1,len
square(i,j)=2
end do
end do
do d=1,10000
square((len/2)-1,(len/2)-1)=square((len/2)-1,(len/2)-1)+1
if(square((len/2)-1,(len/2)-1)>3) then
call toppling((len/2)-1,(len/2)-1)
end if
end do
!open(unit=1,file="\home\sandpile\fortran\file")
do i=1,len
do j=1,len
write(1,*), i,'\t',j,'\t',square(i,j)
end do
print*, '\n'
end do
end program sandpile_model
!This subroutine specifies the evolution rules of the model
recursive subroutine toppling(x,y)
!implicit none
integer, parameter :: len = 20
integer, dimension(len,len) :: square
!real, dimension(len,len) :: blah
integer, intent(in) :: x,y
square(x,y)=square(x,y)-4
square(x+1,y)=square(x+1,y)+1
if(square(x+1,y)>3) then
call toppling(x+1,y)
end if
square(x-1,y)=square(x-1,y)+1
if(square(x-1,y)>3) then
call toppling(x-1,y)
end if
square(x,y+1)=square(x,y+1)+1
if(square(x,y+1)>3) then
call toppling(x,y+1)
end if
square(x,y-1)=square(x,y-1)+1
if(square(x,y-1)>3) then
call toppling(x,y-1)
end if
end subroutine toppling
这里出现的问题是试图 运行 目标文件而不是可执行文件。
非常小/有限的说明:
- 创建目标文件:
gfortran -c <fortran file>
- 创建可执行文件:
gfortran <fortran file>
使用多个源文件时:
- 通过
gfortran <object files>
从单个文件和 link 一起创建对象
- 直接从源文件创建可执行文件
gfortran <fortran files>
注:
- 文件的顺序可能很重要
- 可能需要 link 库以及可执行文件(`-l 选项)
- 可以通过
-o
选项指定输出文件的名称
进一步初步阅读:
- 编译器文档
man gfortran
man make
用于更复杂情况下的自动化。
当我运行下面给出的代码时,它总是给我以下错误:
bash: cannot execute binary file exec format error fortran
此外,文件 "file" 并未在代码中提到的位置创建。我有一个 64 位处理器和 64 位版本的 Ubuntu 16.04,所以这似乎不是问题所在。谁能指出我错在哪里?
program sandpile_model
implicit none
integer, parameter :: len = 20
integer, dimension(len,len) :: square
!real, dimension(len,len) :: blah
!open(unit=1,file="\home\sandpile\fortran\file")
!dummy variables
integer :: i,j,d
do i=1,len
do j=1,len
square(i,j)=2
end do
end do
do d=1,10000
square((len/2)-1,(len/2)-1)=square((len/2)-1,(len/2)-1)+1
if(square((len/2)-1,(len/2)-1)>3) then
call toppling((len/2)-1,(len/2)-1)
end if
end do
!open(unit=1,file="\home\sandpile\fortran\file")
do i=1,len
do j=1,len
write(1,*), i,'\t',j,'\t',square(i,j)
end do
print*, '\n'
end do
end program sandpile_model
!This subroutine specifies the evolution rules of the model
recursive subroutine toppling(x,y)
!implicit none
integer, parameter :: len = 20
integer, dimension(len,len) :: square
!real, dimension(len,len) :: blah
integer, intent(in) :: x,y
square(x,y)=square(x,y)-4
square(x+1,y)=square(x+1,y)+1
if(square(x+1,y)>3) then
call toppling(x+1,y)
end if
square(x-1,y)=square(x-1,y)+1
if(square(x-1,y)>3) then
call toppling(x-1,y)
end if
square(x,y+1)=square(x,y+1)+1
if(square(x,y+1)>3) then
call toppling(x,y+1)
end if
square(x,y-1)=square(x,y-1)+1
if(square(x,y-1)>3) then
call toppling(x,y-1)
end if
end subroutine toppling
这里出现的问题是试图 运行 目标文件而不是可执行文件。
非常小/有限的说明:
- 创建目标文件:
gfortran -c <fortran file>
- 创建可执行文件:
gfortran <fortran file>
使用多个源文件时:
- 通过
gfortran <object files>
从单个文件和 link 一起创建对象
- 直接从源文件创建可执行文件
gfortran <fortran files>
注:
- 文件的顺序可能很重要
- 可能需要 link 库以及可执行文件(`-l 选项)
- 可以通过
-o
选项指定输出文件的名称
进一步初步阅读:
- 编译器文档
man gfortran
man make
用于更复杂情况下的自动化。