Fortran 共轭梯度法-架构x86_64的未定义符号
我今年开始使用fortran,所以如果它是基本的,我很抱歉,但我已经寻找了很长时间的答案,我需要在明天提交:我一直收到错误:Fortran 共轭梯度法-架构x86_64的未定义符号,fortran,Fortran,我今年开始使用fortran,所以如果它是基本的,我很抱歉,但我已经寻找了很长时间的答案,我需要在明天提交:我一直收到错误: 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_solv
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
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_解算器由讲师提供,工作正常。我认为错误可能在于我调用模块或其他东西的方式,但我看不出有什么问题;它们都在同一个文件夹中。在OS X上使用gfortran时,我最好能为所有内容指定“-arch x86_64”标志
您可以尝试使用该标志重新编译所有文件。您是如何编译该程序的?你正在链接cg_solver创建的.o吗?嗨,凯尔,我正在键入gfortran cg_solver.o question2cprogram.f90。.o文件已创建