使用gfortran编译f77内在函数时出错

时间:2015-06-26 23:42:54

标签: fortran gfortran

我开始使用运行Redhat 6.6的HPC。 作为另一个程序的教程步骤,我被要求编译一些旧的F77代码。

我正在运行gfortran 3bar.f行 我收到错误消息:

/tmp/ccgUvoGd.o: In function `MAIN__':
3bar.f:(.text+0x43): undefined reference to `mygetarg_'
3bar.f:(.text+0x61): undefined reference to `mygetarg_'
3bar.f:(.text+0x8a): undefined reference to `mygetarg_'
collect2: ld returned 1 exit status

我认为这与代码中sqrt内在函数的使用有关。我已经对这个错误和gfortran进行了一些搜索,但是我对此特别版本的Fortran进行了一些争吵。

如果有人可以告诉我如何让这些代码工作,我真的很感激,因为这真的不是我正在做的事情。

代码是:

      program Three_bar

      implicit none
      real*8  a1,a2, g1,g2, weight, sum,
     1        l0,d0,sqrt
      intrinsic sqrt
      character*80 inp_fname, out_fname
      character*4  card1
      integer i, ir,iw, numb_args, iargc, numb_iter

      numb_args = iargc()
      if ( numb_args .ge. 2 ) then
         call MYGETARG(1,inp_fname)
         call MYGETARG(2,out_fname)
      else if ( numb_args .eq. 1 ) then
         call MYGETARG(1,inp_fname)
         out_fname = 'rdcs_output'
      else
         inp_fname = 'rdcs_input'
         out_fname = 'rdcs_output'
      endif

      ir = 7
      open (ir, file=inp_fname,status='UNKNOWN',access='SEQUENTIAL')

      iw = 8
      open (iw, file=out_fname,status='UNKNOWN',access='SEQUENTIAL')

      l0 = 1.0
      d0 = 1.0

c loop to spend some cpu - to test recall feature

      sum = 1.0

      numb_iter = 20000
      do 1005 i=1,numb_iter
         sum = (sum*1.00001)**1.001
         if ( sum .gt. 1.0e6 ) sum = 1.0
 1005  continue

c read the data from param file

      weight = (2.d0*sqrt(2.d0)*a1 + a2)*l0*d0
      g1=(2.d0*a1+sqrt(2.d0)*a2)/(2.d0*a1*(a1+sqrt(2.d0)*a2))-1.0d0
      g2 = 1.0d0/(a1 + sqrt(2.d0)*a2) -1.0d0
      write (iw,601) g1,g2,weight

      close (unit=ir,status='KEEP')
      close (unit=iw,status='KEEP')

 501   format(a4,1x,f30.0)
 601   format("g1 = ",e25.16," ",/,"g2 = ",e25.16," ",/,
     1       "weight = ",e25.16," ")

      stop
      end

1 个答案:

答案 0 :(得分:3)

如评论中所述,编译器抱怨缺少MYGETARG的定义,而不是SQRT

你使用该函数的方式让我想起了GETARG这是一个GNU扩展。我的猜测是MYGETARG是一个包装函数,使代码适用于不同的编译器。

由于您使用的是gfortran,我建议您只使用GETARG。然后,您的代码在我的机器上编译,尽管有一些警告。

从长远来看,您应该切换到符合标准的内容,例如GET_COMMAND_ARGUMENT