Reputation: 13
I am getting started with a HPC running Redhat 6.6. As a tutorial step for another program, I am asked to compile some old F77 code.
I am running the line gfortran 3bar.f
I get the error message:
/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
I believe this is related to the use of the sqrt
intrinsic in the code. I have done some searching on this error and gfortran
, but I get some squabbling about particular versions of Fortran for this and that.
I would really appreciate it if someone could advise me on how to get this code to work, as this is really not the point of what I am doing.
The code is:
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
Upvotes: 0
Views: 399
Reputation: 18098
As noted in the comments, the compiler complains about a missing definition of MYGETARG
, not SQRT
.
The way you use that function reminds me of GETARG
which is a GNU extension. My guess would by that MYGETARG
is a wrapper function to make the code work with different compilers.
Since you are using gfortran
, I would suggest to simply use GETARG
instead. Then, your code compiles on my machine, albeit a few warnings.
On the long run, you should switch to something Standard conforming, such as GET_COMMAND_ARGUMENT
.
Upvotes: 3