Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NOOB: multiple definition error when compiling with f77 on FC3

Status
Not open for further replies.

DrCarbon

Technical User
Apr 7, 2005
7
US
Greetings. I'm not much of a fortran programmer so I'm throwing myself on the mercy of the forum. I was given a program that compiles on Compaq Fortran. It also compiles on Sun's fussy compiler when IEEE flags are included. When I invoke the makefile on a vanilla build of FC3 all the objects below compile fine and then during the last step I get the following:

f77 -g -C -o fm97 z3.o initl.o solar.o init_w.o weathr.o solwat.o books.o grow.o regen.o mortal.o decomp.o dsmf.o dtf.o duffrf.o aggprt.o gridprt.o quadrat.o grid.o dla.o height.o aleaf.o awood.o twood.o bole.o branch.o dbranch.o bark.o croot.o froot.o dinco.o alf.o drtf.o fertf.o gddf.o amort.o smort.o init_f.o dyear.o burn.o fmoist.o firefx.o intens.o herb.o bulk.o harvest.o fixfuels.o firekill.o rebooks.o fprint.o fmort.o ran1.o ran2.o ran3.o ran4.o ran5.o ran6.o ran7.o ran8.o gauss1.o gauss2.o gamma.o
init_w.o(.data+0x0): In function `init_w__':
/home/rsgis/facet/fm_97.5/src/init_w.f:3: multiple definition of `site_'
initl.o(.data+0x0):/home/rsgis/facet/fm_97.5/src/initl.f:4: first defined here
collect2: ld returned 1 exit status
make: *** [fm97] Error 1

The name it's complaining about (SITE) exists only as the name of a common block. So what's the source of the complaint? I tried replacing all the include statements with the contents of the include files and got the same error. I tried a local f77 programmer who was stumped. Any thoughts appeciated and I'd be delighted (!) to send a tarball of the code to anybody who is willing to look into this.

I remain, with the greatest respect, your most humble and
obedient servant, etc. etc.

Doc

 
1) Try a named common block.
2) Does SITE exist as a function/subroutine as well?
 
Thanks so much for replying!

1) I think SITE is already a named common block. The include file that names SITE looks like this:
c Site variables for FACET version 97.5, included in Z3.INC.

COMMON/SITE/ xtree, area, ps, dlat, slope, aspect, elev,
2 mdelta, xk, theta, phi, phib, phid, ct, tx, mbgs, megs,
3 mtgs, maxcht, ddbase, degd, wsc, xc0, xc1, smr, smbt,
4 cppt1, cppt2, drzs, ain, fwtr, frtr, fc0, wp0, sff(3)
COMMON/MONTH/ days(12), tmin(12), tmax(12), xt(12), vt(12),
2 xr(12), vr(12), sun(12), rsun(12), ia(12), b(12),
3 plapse(12), tlaps1(12), tlaps2(12), t(0:12), r(12),
4 snow(12), tdf(12), smdf(12), cumppt(0:12)
COMMON/DIRT/ nsl(0:MST), fff(0:MST), dl(0:ML,0:MST),
2 fc(0:ML,0:MST), wp(0:ML,0:MST), wk(0:ML,0:MST),
3 frfs(0:ML,0:MST), frft(0:ML,0:MST)



2) It looks like site_ is initialized in the data section in three objects.

(I've just discovered nm which appears useful)

I guess I need to figure out what that is happening.

[rsgis@kedra src]$ nm -o *.o |grep -i site | grep D
initl.o:00000000 D site_
init_w.o:00000000 D site_
weather.o:00000020 D site_

The error I get refers to multiple definitions in initl.o and init_w.o - I guess there is a thrid in weather.o

The other variables in site.inc don't appear more than once witht ehsymbol value "D":
[rsgis@kedra src]$ nm -o *.o |grep -i dirt | grep D
initl.o:000000a0 D dirt_
[rsgis@kedra src]$ nm -o *.o |grep -i month | grep D
init_w.o:000000a0 D month_
weather.o:000000e0 D months_
[rsgis@kedra src]$

This make any sense?

Doc


 
Don't know very much about the F77 compiler on Sun: I've only ever used C and C++ on Sun.

1) Is there an option that says 'do not define the common block in the object file'?
2) Is there a block data segment all the common blocks that you use are declared?
3) Do these IEEE compliant flags do anything special other than checking syntax?
4) Is site used anywhere else as a declared common block i.e. not from the header file. If it is, is the number of elements the same and have all the variables declared to be of the same type? Missing out one declaration could make the common block a different size: as a result, it won't combine the blocks as the same common block. Remember I-N is integer, everything else is real unless explicitly declared.
 
I'm not on a Sun, but using g77 compiler in Linux. Is there such an option? I'm reading the man page now, but not finding anyhting obvious.
 
Ah ha. Is this it?

18. Known Causes of Trouble with GNU Fortran

18.4.2 Multiple Definitions of External Names

g77 doesn't allow a common block and an external procedure or BLOCK DATA to have the same name. Some systems allow this, but g77 does not, to be compatible with f2c.

 
That is what I asked earlier - is site a function or subroutine as well? Just tried the following and it seems to work
The include file (cblk.inc)
Code:
      character*256 str
      common /cblk/str
The subroutine file (callee.f)
Code:
      subroutine usecom
      include 'cblk.inc'
      print *, str
      return
      end
The program (caller.f)
Code:
      program main
      include 'cblk.inc'
      external usecom
      str = 'gotcha'
      call usecom
      stop
      end
Compilation
Code:
g77 caller.f callee.f -ocaller
 
Yes. That works for me too. Following the syntax of the makefile I'm trying to use:

Code:
g77 -c -o callee.o callee.f
g77 -c -o caller.o caller.f
g77 -o caller caller.o callee.o

And nm doesn't return anything with symbol D which is what is supposed to happen

Code:
nm *.o | grep D

I have to go out of town for a few days, but hopefully I'll have something more intelligent to report after looking at it. Thanks SOOOOOOO much for your help.

Doc
 
Think you need a -g (debug symbols). Another idea would be to drop the space between the -o and the object file.
 
Ok. I've found the problem. I found a multiple declaration using data in two subroutines.

Reworking the previous example, this is what is happening.


This is the cblk.inc file:
Code:
      common /cblk/j

This is the callee.f file:
Code:
      subroutine usecom
      include 'cblk.inc'
      data j /5/
      return
      end

This is the callee2.f file:
Code:
      subroutine usecom2
      include 'cblk.inc'
      data j /5/
      return
      end

This is the caller.f file:
Code:
      program main
      include 'cblk.inc'
      call usecom
      call usecom2
      print *, j
      stop
      end

This is a script that shows the compiler call with nm:
Code:
rm *.o
g77 -g -c -o callee.o callee.f
nm callee.o
g77 -g -c -o callee2.o callee2.f
nm callee2.o
g77 -g -c -o caller.o caller.f
nm caller.o
g77 -g -o caller caller.o callee.o callee2.o

That gives the SAME multiple definition error I was getting before.

So, new question: Is there anyway to make g77 compile main as it is coded above?

Thanks, Doc
 
Oops. I was wrong. There isn't a repeat data statement in the code I'm trying to work with. So, disregard the post above. I'm still totally lost! I just know that site_ is being defined multiple times and can't figure out where. If anybody wants to try the code and save me from putting my head through the screen email me at DrCarbon-at-gmail-dot-com and I'll send it to you.
 
Looks like the problem is that the author didn't know whether usecom or usecom2 will be called first so both routines initialized j. A way around is to remove the data statements in usecom and usecom2 and to add a block data segment.

Add the following to caller.f
Code:
      block data
      include 'cblk.inc'
      data j /5/
      end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top