我是Fortran的新手,所以也許這是一個直截了當的問題,但我還沒有找到任何通過查看SO上的類似帖子來工作的解決方案。Fortran模塊鏈接失敗
我的問題是,當我試圖編譯我的主要程序,通過執行
gfortran -c dfft.f
gfortran -c srft.f95
gfortran -c testsrft.f95
- 使用在srft.f95定義的模塊srftModule testsrft.f95
gfortran dfft.o srft.o testsrft.o -o testsrft
(子程序S IN srftModule需要dfft.f中的Fortran77代碼),我得到的鏈接錯誤
testsrftF.o: In function `MAIN__':
testsrftF.f95:(.text+0x98): undefined reference to `fftofmat_'
collect2: ld returned 1 exit status
該模塊的定義如下
module srftModule
implicit none
contains
... (some subroutines)
subroutine fftofmat(A)
implicit none
real*8, dimension(:, :), intent(inout) :: A
...
end subroutine fftofmat
... (some more subroutines)
end module srftModule
而在我的主文件,我有
program testsrft
use srftModule
implicit none
...(code to initialize a 10x10 matrix A)
call fftofmat(A)
end program testsrft
爲什麼連接器抱怨?
鏈接器找不到'.mod'文件,請參閱http:// stackoverflow。com/questions/8855896/specify-directory-where-gfortran-should-look-for-modules –