2014-11-25 84 views
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 

我认为这个错误可能和我一样调用模块或其他东西,但我看不出有什么问题;他们都在同一个文件夹中。

+3

你是如何编译程序的?你链接由cg_solver创建的.o吗? – Exascale 2014-11-25 06:36:26

+0

嗨凯尔,我在输入“gfortran cg_solver.o question2cprogram.f90”。 .o文件已经创建 – malonej 2014-11-25 11:54:49

回答

0

我有更好的运气使用gfortran时,在OS X上

可以尝试重新编译与标志的所有文件指定“-arch x86_64的”标志的一切。

相关问题