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

LNK2005 problems within Fortran modules

bhaskarsg1
Beginner
1,055 Views
Hi,
I am trying to recompile an oldmulti module Fortran programme, which have a common block included in all modules. These previously compiled well in VAX Fortran environment as well as recently in MS Developer Studio Fortran PowerStation 4.0 environment. In the latter, it gives warnings about multiply defined symbols. However, I am not being able to invoke the same switch (which comes as default in MS Fortran PowerStation) for Intel Fortran environment.
Can something be done other than trying to separate out the multiply defined symbols in the common block?

BSG
0 Kudos
3 Replies
mecej4
Honored Contributor III
1,055 Views
Please show an example of the multiply defined symbols in the common block. Variable names in a common block in F77 code are not put into the compiled object; only the name of the common block is.

For example, with prg.f containing
[fortran]
program tst
double precision A, B, C
common /xyz/A, B, C
data A,B,C/1d0,2d0,3d0/
call sub()
end[/fortran]

and sub.f containing
[fortran]
subroutine sub
double precision A,B,C,D
common /xyz/A,B,C,D
! data A/4.5d0/
write(*,*)A,B,C,D
return
end
[/fortran]

there is no problem. A dump of the two .OBJ files shows "D _XYZ" for prg.obj and "C _XYZ" for sub.obj.

If, however, the DATA statement in sub.f is activated, there is a duplicate initialization of the common block; the dumps of the two .OBJ files both show "D _XYZ" and the linker rightly complains
[bash]sub.obj : error LNK2005: _XYZ already defined in prg.obj
prg.exe : fatal error LNK1169: one or more multiply defined symbols found
[/bash]
There is a linker option /FORCE:multiple, which changes the linker messages to
[bash]sub.obj : warning LNK4006: _XYZ already defined in prg.obj; second definition ignored
prg.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
[/bash]

but its use except in an example such as this may be compared to shooting oneself in the foot.

You must use this migration task as an opportunity to fix this bug in the code. Your code is in violation of the Fortran-77 standard. Attempting to replicate the quirks of an old compiler/OS combination on a new platform is not advised.

0 Kudos
bhaskarsg1
Beginner
1,055 Views
Thanks......undefining the data initialisation in the sub modules did the trick. Just as a curiosity asking about the second piece of solution you had given - can you get the linker option through the property page gui or do you have to explicity add it on:
0 Kudos
Lorri_M_Intel
Employee
1,055 Views
You have to explicitly add it on ... it's too easy to abuse to make it too simple to set.
0 Kudos
Reply