Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran未定义对u[子例程名称]的引用_Fortran_Gfortran_Numeric_Numerical Recipes - Fatal编程技术网

Fortran未定义对u[子例程名称]的引用

Fortran未定义对u[子例程名称]的引用,fortran,gfortran,numeric,numerical-recipes,Fortran,Gfortran,Numeric,Numerical Recipes,我正在用Fortran 90 vol2helloBessel测试书中所写的数值公式 program helloBessel use nrtype use nr, ONLY: flmoon, bessj0 implicit none integer(I4B) :: n = 200, nph = 2, jd real(SP) :: x, frac, ans call flmoon(n, nph, jd, frac) write (*,*) jd x = jd**0.25_sp ans = bes

我正在用Fortran 90 vol2
helloBessel
测试书中所写的数值公式

program helloBessel
use nrtype
use nr, ONLY: flmoon, bessj0
implicit none

integer(I4B) :: n = 200, nph = 2, jd
real(SP) :: x, frac, ans

call flmoon(n, nph, jd, frac)
write (*,*) jd
x = jd**0.25_sp
ans = bessj0(x)
write (*,*) "Hello, Bessel: ", ans
end program helloBessel
它给出了以下错误:

gfortran -o bessel nr.o nrtype.o helloBessel.f90 
/tmp/cchJfVZl.o: In function `MAIN__':
helloBessel.f90:(.text+0x28): undefined reference to `flmoon_'
helloBessel.f90:(.text+0xb4): undefined reference to `bessj0_s_'
collect2: error: ld returned 1 exit status
/tmp/cc76cg5g.o: In function `MAIN__':
helloTest.f90:(.text+0x1a): undefined reference to `test_'
collect2: error: ld returned 1 exit status
我试着做了一个小例子,以防万一:

program helloTest
use nrtype
use nr, ONLY: test
implicit none

real(SP) :: z, t
call test(z, t)
write (*,*) t

end program helloTest
我是这样编译的:

gfortran -c nr.f90
gfortran -c nrtype.f90
gfortran -o test nr.o nrtype.o helloTest.f90
它仍然给出了这个错误:

gfortran -o bessel nr.o nrtype.o helloBessel.f90 
/tmp/cchJfVZl.o: In function `MAIN__':
helloBessel.f90:(.text+0x28): undefined reference to `flmoon_'
helloBessel.f90:(.text+0xb4): undefined reference to `bessj0_s_'
collect2: error: ld returned 1 exit status
/tmp/cc76cg5g.o: In function `MAIN__':
helloTest.f90:(.text+0x1a): undefined reference to `test_'
collect2: error: ld returned 1 exit status
这是代码或编译过程中的问题吗?我做错了什么? 我的问题和其他人不同,因为我的版本足够高,不会引起问题,而且我已经告诉编译器所有的文件,这并不能解决问题

来自模块的相关代码

MODULE nrtype
    INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)
    INTEGER, PARAMETER :: SP = KIND(1.0)
END MODULE nrtype
更新:根据Vladimir F answer,我创建了test.f90

function test(x, y)
real, intent(in) :: x
real, intent(out) :: y

y = x + 2
return
end function test
更新的
real(SP)::z=1,t
在helloTest中,用

gfortran -o test test.f90 nr.o nrtype.o helloTest.f90

我的成绩是3.0000。谢谢大家!

显示的代码中没有子例程
test
。接口只承诺一个,但您必须实际提供它


与第一个错误类似,您必须实际添加具有
flmoon、bessj0
实现的代码。谷歌搜索显示它应该在
bessj0.f90
中,但我自己无法测试它。

对不起,我不明白你的解决方案。问题是我必须命名接口吗?不,您必须向编译中添加其他源文件。您正在编译的那些文件不够。另请参阅我刚才所做的编辑。对,bessj0包含在vol1中,我没有意识到它也必须提供。现在我在Fortran 77中遇到了一些问题(虽然它应该是向后兼容的,它会在数据处产生语法错误),但我会将其更改为测试它是否有效。在C21中学习Fortran的人可能会查看参考资料的附录,其中解释了各种内在的
bessel
例程。无需使用NR(或任何其他)代码。