【发布时间】:2015-11-18 10:19:21
【问题描述】:
目标:使用子程序load_things 加载su2 类型的结构库。
运行gfortran simple.f90 产生
Undefined symbols for architecture x86_64:
"_load_things_", referenced from:
_MAIN__ in cc7DuxGQ.o
(maybe you meant: ___myclass_MOD_load_things_sub)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
主程序如下:
program simple
use myClass
implicit none
integer :: nThings
type ( su2 ) :: reflections
call load_things ( nThings, reflections )
end program simple
模块定义为:
module myClass
implicit none
type :: su2
integer :: matrix_obj ( 1 : 2, 1 : 2 )
contains
private
procedure, nopass, public :: load_things => load_things_sub
end type su2
private load_things_sub
contains
subroutine load_things_sub ( nThings, U )
integer, intent ( out ) :: nThings
type ( su2 ), intent ( out ), allocatable :: U ( : )
nThings = 2
allocate ( U ( nThings ) )
U ( 1 ) % matrix_obj = reshape ( [ 0, 1, 1, 0 ], [ 2, 2 ] )
U ( 2 ) % matrix_obj = reshape ( [ 0, 1, 1, 0 ], [ 2, 2 ] )
end subroutine load_things_sub
end module myClass
研究了以下网页,没有成功:Correct use of modules, subroutines and functions in fortran,
Fortran 90 - to transmit values from main subroutine to the functions and other subroutines,
Fortran: Calling a function in a module from a procedure in another module,
Fortran 90 How to call a function in a subroutine in a module?
【问题讨论】:
标签: module fortran gfortran subroutine