Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Problems with Block Data

Gordon_B_
Beginner
398 Views

Hello Forum Members:

I'm trying to resurrect an ancient FORTRAN IV program from the 1960s.  I'm having trouble with the Linker telling me that a symbol is multiply defined.    I get these messages, where CSTAR is a Common block, PERDAT is another BLOCK DATA file

Severity    Code    Description    Project    File    Line    Suppression State
Error        fatal error LNK1169: one or more multiply defined symbols found        (in TND4729)       
Error        error LNK2005: _CSTAR already defined in TND4729.obj                    (in Perdat.obj)

Can anyone help me to sort out this mess.

My first question to help me understand what is going on is: Where does the block data get inserted in the program?

Regards,

Gordon B

 

 

 

   

 

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
398 Views

This happens when a COMMON contains initializations in more than one program unit. All such initializations should be in a BLOCK DATA subprogram only. Look in TND4729 and move any initialization of variables in common CSTAR to the BLOCK DATA subprogram.

A common technique for ensuring that a BLOCK DATA subprogram is included is to name it in an EXTERNAL statement in the main program. Otherwise it's just another program unit that is compiled and linked into the application.

0 Kudos
mecej4
Honored Contributor III
398 Views

With BLOCKDATA placed in a separate source file by itself, you run the risk of leaving out the corresponding .OBJ file at link time. If this happens, the common blocks may be used in other subprograms without their contents having been initialized, and there may be no compiler or linker error messages to warn you of that. Steve's comment shows you how to keep that from happening.

0 Kudos
Reply