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

interfaces in modules

netphilou31
New Contributor III
440 Views

Again I have experienced some troubles converting CVF project to IVF. I have put some interface declarations into one module and made this module available by a use statement and I get some errors in the link steps.

For example the module contains many declarations like:

interface

integer(4) function GetListNodeByID(dwNodeID, ID)

!DEC$ ATTRIBUTES STDCALL :: GetListNodeByID

!DEC$ ATTRIBUTES VALUE :: dwNodeID

!DEC$ ATTRIBUTES REFERENCE :: ID

integer(4) dwNodeID

character*(*) ID

end function

end interface

and when I use the module into a routine for calling the GetListNodeByID function the linker gives :

error LNK2005: getlistnodebyid is already defined in DocumentWrapper.obj

(DocumentWrapper is the module being used). This is very strange because I have put some interface declarations into other modules and I did not get this problem. For information, this routine name is also associated (in the same module) to an integerpointer with a declaration :

integer(4) :: pGetLitNodeByID = 0

pointer (pGetLitNodeByID, GetListNodeByID)

because it is loaded dynamically by a GetProcAddress API callin another procedure hat uses the module and moreover this module contains also internal routines (declared after a contains statement). For all external routines calling procedures internal to the module no link error is issued but for all external procedures calling routines that are only declared by interface statement I get this error. I have tried to put the declarations into a different module (as well as the pointer associations) but without more success. Finally, I can also say that I did not get any problems with CVF.

Has somebody any idea about what could happen ? Did I use modules not in a normal way ? what changed from CVF?

Thanks,

0 Kudos
3 Replies
Steven_L_Intel1
Employee
440 Views
I'd need to see the whole module to understand the link error, but I do know of a difference from CVF that you are may be encountering.

It is an error to have an INTERFACE in a module and then name that intetface in a POINTER statement in a contained procedure or in another routine that USEs the module. CVF didn't catch this error, Intel Fortran does. The reason it is an error is that the POINTER changes the attributes of the use or host-associated symbol from an external routine to a pointer routine. The Fortran language says that definitions are effectively "locked" once the CONTAINS is seen or when the module is USEd.

The fix for this is to either move the POINTER declaration up into the module next to the interface, or move the interface down into the routine declaring the pointer.

Now what puzzles me is that the Intel compiler gives an error message for this situation - I can't think of a way you'd get a duplicate symbol link error. So I will go back to saying I'd need to see a complete example to understand what is happening.
0 Kudos
netphilou31
New Contributor III
440 Views

Thank you steeve, as usual your advices are of great help.This part of the modules/interfaces/function pointers is now more clear for me. However, What is still strange for me is that the pointer declaration was put in the same module as the interface statement (before any contained procedures). The pointer initialization (by getprocaddress) was made in routine r1 and the use of the interfaced (external) procedure in routine r2 both using the module.

I will try to manage this differently and if I have some time, I will try to build a smaller project to try to reproduce the problem.

Finally, if I need to send to you some ZIP file containing the project, how can this be done ?

Again many thanks,

0 Kudos
Steven_L_Intel1
Employee
440 Views
You would submit an issue to Intel Premier Support and attach the ZIP file.
0 Kudos
Reply