views:

391

answers:

3

Hi,

I am porting the application with old fortran compiler and old visual studio(VC5) to new fortran compiler 11 and visual studio 2005. Application contains both 'C' and fortran code. I am compiling the fortran code and creating library called server_lib.lib(library is createing with some warnings) and linking to the 'C' code. while linking application is giving some below linking errors.

2>Linking...
2>server_lib.lib(Preparx.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Query.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Utm.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Runvhf.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(PFLTPV.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Qdesic.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Headach.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Plotky.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Terrain.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Morpho.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Diflos.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Micro.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(OpenGL_F.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Violet.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Fieldp.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Step.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(White.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>.\Debug/Server.exe : fatal error LNK1169: one or more multiply defined symbols found

above "serverstuff" is defined in server.for file and this server.for is included in all above files. Please find the below code block from server.for file. But the serverstuff variable defined only once in server.for file.

INTEGER iErrPipe !error code for pipe i/o
INTEGER clientIndex !index into client list
CHARACTER*136 Buffer(17) !buffer for pipe i/o
CHARACTER dBuffer(2313) !buffer for pipe i/o
EQUIVALENCE(dBuffer,Buffer)
COMMON/serverstuff/clientIndex,dBuffer

DATA dBuffer(2313)/0/

Why the above code is giving redeclaration error? How it worked with previous fortran compiler? When I am commenting the "COMMON/serverstuff/clientIndex,dBuffer" line then it's linking perfectly, but the application is crashed..

Please give me any idea as I don't know about fortran language.

+1  A: 

The problem is that the meaning of common blocks (the word COMMON is for that) has somehow changed between the versions. Previously the compiler figured out that the common blocks in several files must be merged into one variable and now it does include a copy of variable into every .obj file and this causes link error later. You have to read the new version manual on how the common blocks work in the new version - that will likely shed light onto how to overcome the problem.

sharptooth
Hi Thanks for your reply.. As you said, server.for is included in some of the other files, though it is a global variable, serverstuff is giving redecleration problem when linking libraries. How can i split that COMMON data in such a way that, it should include in all required files and should not give redecleration error?? I am using fortran 11.0.035 compiler now. As per my investigation the COMMON decleration is corret, but i am not sure about it.Thanks in advance..
A: 

Hi Thanks for your reply.. As you said, server.for is included in some of the other files, though it is a global variable, serverstuff is giving redecleration problem when linking libraries. How can i split that COMMON data in such a way that, it should include in all required files and should not give redecleration error?? I am using fortran 11.0.035 compiler now. As per my investigation the COMMON decleration is corret, but i am not sure about it. Thanks in advance..

A: 

I am not sure what is happening but a problem that used to occur with mixed language programs was processing or loading of language specific things. For example if you have a main function written in C and a fortran subroutine which does IO then linking using the C system may not load the fortran io libraries because it does not know anything about them.

I am wondering if you have a main function in C or C++ the linker does not know that the common block is a global variable. You could try putting

extern char[2313] _SERVERSTUFF;

before your function main. you may need to play with removing the underscore and possible the case of SERVERSTUFF

hugok