Gues
Gues

Reputation: 11

Duplicate Symbol Error When trying to Compile Fortran Code

I'm trying to compile several Fortran subroutines in addition to a main program and block data file on a Macbook Air (Big Sur 11.6). I'm using gfortran with the specific flag,

gfortran -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib  *.f08

Currently using the -L flag is the only way I can get most Fortran compilations to work from now on.

The error that I get after using the above compilation command is

duplicate symbol '_reals_' in:
/var/folders/rt/z3gtmqkn3zsg9n2x0pm6jw200000gn/T//ccXBiLt3.o
/var/folders/rt/z3gtmqkn3zsg9n2x0pm6jw200000gn/T//ccC8EISk.o
ld: 1 duplicate symbol for architecture x86_64
collect2: error: ld returned 1 exit status

I'm using GNU Fortran 11.1.0

I suspect the two problem causing Fortran files in the collection that I'm trying to compile are the block data file, block_data.f08, and ssivel.f08, both below. The code is the Fortran77 examples included in the appendices of the book, 'Molecular Dynamics Simulation: Elementary Methods', by J.M. Haile.

        subroutine ssivel
      2 implicit real*8 (a-h, o-z)
      3 
      4    real*4 roulet
      5    common /intgrs/ ints(7)
      6    common /reals/ rl(26)
      7    common /vel/ x1(256), y1(256), z1(256)
      8 
      9    equivalence (ints(4), natom)
     10    equivalence (rl(9), fnatom), (rl(23), velsq)
     11 
     12    data sumx, sumy, sumz, velsq /4*0.d0/
     13    mseed = -30509
     14 
     15 !...assign random velocity components on (-1, +1); roulet is given in appendix h
     16    do 100 i = 1, natom
     17       x1(i) = roulet(mseed)
     18       y1(i) = roulet(mseed)
     19       z1(i) = roulet(mseed)
     20       sumx = sumx + x1(i)
     21       sumy = sumy + y1(i)
     22       sumz = sumz + z1(i)
     23 100 continue
     24 
     25 !...scale velocities so that total linear momentum is zero; see eq. (5.28)
     26    do 120 i = 1, natom
     27       x1(i) = x1(i) - sumx/fnatom
     28       y1(i) = y1(i) - sumy/fnatom
     29       z1(i) = z1(i) - sumz/fnatom
     30       velsq = velsq + x1(i)**2 + y1(i)**2 + z1(i)**2
     31 120 continue
     32 
     33 !...scale velocities to set-point temperature or to set-point total energy
     34    call sscale(0.)
     35    return
        block data
      2 implicit real*8(a-h, o-z)
      3 
      4    common /deriv3/ x3(256), y3(256), z3(256)
      5    common /deriv4/ x4(256), y4(256), z4(256)
      6    common /deriv5/ x5(256), y5(256), z5(256)
      7    common /force/ fx(256), fy(256), fz(256)
      8    common /nablst/ list(15000), npoint(256)
      9    common /rdf/ ngofr(300), gr(300)
     10    common /reals/ rl(26)
     11 
     12    equivalence (rl(17), sumenr),(rl(18),sumvir),(rl(19), sumvsq)
     13 
     14    data x3/256*0.d0/,y3/256*0.d0/,z3/256*0.d0/
     15    data x4/256*0.d0/,y4/256*0.d0/,z4/256*0.d0/
     16    data x5/256*0.d0/,y5/256*0.d0/,z5/256*0.d0/
     17    data fx/256*0.d0/,fy/256*0.d0/,fz/256*0.d0/
     18    data ngofr/300*0/
     19    data list/15000*0/, npoint/256*0/
     20    data sumenr, sumvir, sumvsq/3*0.d0/
     21 
     22    end

Upvotes: 1

Views: 385

Answers (1)

TJahns
TJahns

Reputation: 299

There is a restriction on block data, that you might not be aware of:

The same labeled common block cannot be specified in more than one block data subprogram in the same executable program.

i.e.:

equivalence (rl(9), fnatom), (rl(23), velsq)

data sumx, sumy, sumz, velsq /4*0.d0/

and

   12    equivalence (rl(17), sumenr),(rl(18),sumvir),(rl(19), sumvsq)
[...]
   20    data sumenr, sumvir, sumvsq/3*0.d0/

both try to initialize the reals common block which is disallowed.

Upvotes: 1

Related Questions