我想編譯一個使用一堆模塊的fortran程序。我編譯時遇到錯誤,這讓我發瘋。該錯誤是源於通過添加一個子程序,併發生當我嘗試重新編譯程序:Fortran編譯錯誤 - 未定義的參考
主要程序包括以下兩行:
-
call read_step(nStepOne,molOne)
call read_step(nStep,mol)
-
這是調用文件「fileio.f90」中的一個子例程:
-
subroutine read_step(n,tape)
implicit none
integer, intent(in) :: tape
integer, intent(out) :: n
character(len=6) :: dum
rewind(tape)
read (tape,*)
read (tape,*) dum, n
rewind(tape)
return
!
end subroutine read_step
-
當我嘗試編譯它,下面的錯誤出現:
ifort -o SpIdMD.x *.o -static-intel -openmp
SpIdMD.o: In function `MAIN__':
SpIdMD.f90:(.text+0x3b2): undefined reference to `read_step_'
SpIdMD.f90:(.text+0x3c5): undefined reference to `read_step_'
make: *** [SpIdMD.x] Error 1
到同一模塊中的子程序調用其他沒有給出任何錯誤,我只是不查看對「舊子程序」和我剛剛創建的子程序的調用之間的區別。
這些 「老子程序」,這沒有給出任何投訴中的一個的一個例子是:
在主程序:
call get_dim(n_atom,nSnap,mol)
在fileio.f90:
subroutine get_dim(n,n_snap,tape)
implicit none
integer,intent(in) :: tape
integer,intent(out) :: n, n_snap
integer :: m
rewind(tape)
read (tape,*,err=1,end=2) n
rewind(tape)
m = 0
do while (.true.)
read (tape,*,err=1,end=3)
m = m +1
end do
3 n_snap = m/(n + 2)
if (m.ne.(n_snap*(n + 2))) stop 'unexpected end of input file'
rewind(tape)
return
!
1 stop 'error in input file'
2 stop 'unexpected end of input file'
end subroutine get_dim
我完全不知道爲什麼會出現這種行爲。如果有人能幫我解決這個噩夢,我會很感激。謝謝!
你運行'make clean'然後再次嘗試make嗎? –
是的,但沒有解決任何問題。我確保fileio.o(包含模塊)已更新。 – user2296052