0
我今年開始使用fortran,所以我道歉,如果它是基本的,但我一直在尋找一個答案很長時間,我需要明天交出:(我不斷收到錯誤:當模塊cg_solver從講師給出正常工作共軛梯度法 - 架構x86_64的未定義符號
Jamess-MacBook-Pro:Coursework2 james$ gfortran Question2cprogram.f90
gfortran: warning: couldn’t understand kern.osversion ‘14.0.0
Undefined symbols for architecture x86_64:
"___cg_solver_MOD_cg", referenced from:
_MAIN__ in ccg9ePxI.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
這是一個相對簡單的程序,只是底層的值到子程序「CG」從一個模塊cg_solver稱爲
program Question2c
use cg_solver
use numeric_kinds
use csr_sparse_matrix
implicit none
real(dp) :: tol
real(dp), dimension(:), allocatable :: x, b, real_x
integer :: n, no_iterations
type(sp_matrix) :: a
n = 4
allocate(real_x(n))
real_x(1)=1
real_x(2)=7
real_x(3)=4
real_x(4)=13
allocate(b(n))
b(1)=30.0
b(2)=34.0
b(3)=28.0
b(4)=152.0
allocate(x(n))
allocate(a%matrix_entries(8))
a%matrix_entries(1)=4.0
a%matrix_entries(2)=2.0
a%matrix_entries(3)=3.0
a%matrix_entries(4)=1.0
a%matrix_entries(5)=7.0
a%matrix_entries(6)=2.0
a%matrix_entries(7)=1.0
a%matrix_entries(8)=11.0
allocate(a%column_no(8))
a%column_no(1)=1.0
a%column_no(2)=4.0
a%column_no(3)=2.0
a%column_no(4)=4.0
a%column_no(5)=3.0
a%column_no(6)=1.0
a%column_no(7)=2.0
a%column_no(8)=4.0
allocate(a%row_start(5))
a%row_start(1)=1.0
a%row_start(2)=3.0
a%row_start(3)=5.0
a%row_start(4)=6.0
a%row_start(5)=9.0
tol = 10**(-10)
call cg(a,b,x,n,tol,no_iterations)
print *, x
deallocate(a)
deallocate(x)
deallocate(real_x)
end program Question2c
我認爲這個錯誤可能和我一樣調用模塊或其他東西,但我看不出有什麼問題;他們都在同一個文件夾中。
你是如何編譯程序的?你鏈接由cg_solver創建的.o嗎? – Exascale 2014-11-25 06:36:26
嗨凱爾,我在輸入「gfortran cg_solver.o question2cprogram.f90」。 .o文件已經創建 – malonej 2014-11-25 11:54:49