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

COMMON blocks

mdfischer
Beginner
484 Views
I am using common blocks in a single include file, then using this include file in each subroutine. I have 5 common blocks in this file, and all but one read fine. For some reason, one of them keeps giving me the error:

GetData.obj : error LNK2005: _INFO already defined in Readzip.obj
WriteData.obj : error LNK2005: _INFO already defined in Readzip.obj
WriteHeader.obj : error LNK2005: _INFO already defined in Readzip.obj
Debug/ReadWind.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

Where GetData,WriteData,WriteHeader are subroutines called by another subroutine, Readzip. The common block is named "info". Why is this happening for this block, but not the other common blocks?

Also - any suggestions on better methods to share data between subroutines this way? I don't particularly like common blocks, but I also don't want to pass these variables as arguments.

Thanks
michele
0 Kudos
2 Replies
james1
Beginner
484 Views
I suspect you are initializing some data within this common block. You can legally only do this in a BLOCK DATA program unit, or do it at runtime. That should eliminate your link errors.

If you want a "cleaner" method of sharing data, i.e. avoiding global variables, changing your common block to a derived type and passing the resulting single variable is my choice.

James
0 Kudos
mdfischer
Beginner
484 Views
That did the trick! Thanks for your help.
0 Kudos
Reply