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

Urgent three Fortran DLL problems in VF....

Xj_Kong
Novice
857 Views

!Fortran Dll Problems

**********************************************************!1). Overload Operators in one Dll cannot be indentified

! in the main program

!

**********************************************************! The common variables must be visible by copying MyMod.mod file to the working dir

! I can not use overloaded '+'!!!!

!eg..

Module MyMod

! MyMod.f90

! FUNCTIONS/SUBROUTINES exported from MyMod.dll:

! MyMod - subroutine

TYPE point

REAL*8::X,Y,Z

END TYPE point

TYPE VECTOR

REAL*8::X,Y,Z

END TYPE VECTOR

INTERFACE OPERATOR(+)

!DEC$ ATTRIBUTES DLLEXPORT::INTERFACE OPERATOR(+)

MODULE PROCEDURE VEC_ADD

END INTERFACE

contains

!------------------------------------------------------------------

! Arithmetic Ops

!------------------------------------------------------------------

FUNCTION VEC_ADD(V1,V2)Result(VEC_ADD_rst)

!DEC$ ATTRIBUTES DLLEXPORT::VEC_ADD

TYPE(VECTOR),INTENT(IN)::V1,V2

TYPE(VECTOR)::VEC_ADD_rst

VEC_ADD_rst%X=V1%X+ V2%X

VEC_ADD_rst%Y=V1%Y+ V2%Y

VEC_ADD_rst%Z=V1%Z+ V2%Z

END FUNCTION VEC_ADD

Module MyMod

program usedll

use MyMod !,only:point,vector,OPERATOR(+),Pnt_Add,suba,subb,int2str,FunC

type(point)::p

type(vector)::v

p=point(0d0,1d0,2d0)

v=vector(1d0,0d0,1d0)

type*,(p+p)

end program usedll

!**************************************************************

!2). How can a program run by avoiding to call the Dll subroutines if through testing the Dll file does not exist?

!**************************************************************

!**************************************************************

!3). How to share file units in the Dll and calling program?

!**************************************************************

I'm experiencing unexpected behavior when using fortran formatted output to a text file from within my fortran DLL.

In the main program,I open file unit 10 and append some text within dll to the same unit 10, but there are two files generated and fort.10 is obviously from dll.

Fortran runtime libraries as DLLs

A copy of the Fortran runtime is provided as a collection of DLLs. Dynamic linking with the Fortran runtime allows multiple executables to use the same copy of the Fortran runtime, thereby reducing the size of each executable. It also maintains continuity of I/O between code residing in a main program and code residing in a DLL. For example, a unit number can be opened in a main program and passed to code in a DLL. The DLL will be able to perform I/O operations on the opened unit. It is not possible to do this with a statically linked runtime because the program and the DLL would each have its own copy of the runtime and the runtime in the DLL would not be aware of connections made by the runtime in the main program. The new -nstaticlib switch links with the DLL runtime.

0 Kudos
7 Replies
Steven_L_Intel1
Employee
857 Views
The !DEC$ ATTRIBUTES DLLEXPORT goes in the routine you are exporting (VEC_ADD), not in the interface block for a generic operator. Just remove it from the interface block.
0 Kudos
Xj_Kong
Novice
857 Views

I did what you suggested, but I still got this error. Do you have more clue or you can try yourself?

--------------------Configuration: UseDLL - Win32 Debug--------------------

Linking...

UseDLL.obj : error LNK2001: unresolved external symbol _MyMod_mp_PNT_ADD@12

Debug/UseDLL.exe : fatal error LNK1120: 1 unresolved externals

Error executing link.exe.

UseDLL.exe - 2 error(s), 0 warning(s)

0 Kudos
Andrew_Smith
Valued Contributor I
857 Views
Your module has no end module statement so it would not compile as is. Please post the actual code.
0 Kudos
Steven_L_Intel1
Employee
857 Views
The linking error involves the caller of the DLL, which you have not shown. The most likely reason is that you are not linking in the DLL export .LIB when you link the executable.
0 Kudos
mecej4
Honored Contributor III
857 Views
Do you have more clue or you can try yourself?

Here is a clue: if there has been a crime committed, it's probably not the compiler that is responsible.
0 Kudos
Xj_Kong
Novice
857 Views
[fortran]!Fortran Dll Problems
**********************************************************!1). Overload Operators in one Dll cannot be indentified
! in the main program
!
**********************************************************! The common variables must be visible by copying MyMod.mod file to the working dir
! I can not use overloaded '+'!!!!
!eg..
Module MyMod
! MyMod.f90 
! FUNCTIONS/SUBROUTINES exported from MyMod.dll:
! MyMod - subroutine 
TYPE point
REAL*8::X,Y,Z
END TYPE point
TYPE VECTOR
REAL*8::X,Y,Z
END TYPE VECTOR

INTERFACE OPERATOR(+)
MODULE PROCEDURE VEC_ADD
END INTERFACE
contains

!------------------------------------------------------------------
! Arithmetic Ops
!------------------------------------------------------------------
FUNCTION VEC_ADD(V1,V2)Result(VEC_ADD_rst)
!DEC$ ATTRIBUTES DLLEXPORT::VEC_ADD
TYPE(VECTOR),INTENT(IN)::V1,V2
TYPE(VECTOR)::VEC_ADD_rst
VEC_ADD_rst%X=V1%X+ V2%X
VEC_ADD_rst%Y=V1%Y+ V2%Y
VEC_ADD_rst%Z=V1%Z+ V2%Z
END FUNCTION VEC_ADD
End Module MyMod

!------------------------------------------------------------------!
! Main Program goes here
!------------------------------------------------------------------!
program usedll
use MyMod !,only:point,vector,OPERATOR(+),Pnt_Add,suba,subb,int2str,FunC
type(point)::p
type(vector)::v
p=point(0d0,1d0,2d0)
v=vector(1d0,0d0,1d0)
type*,(p+p)
end program usedll

[/fortran]
0 Kudos
Andrew_Smith
Valued Contributor I
857 Views

You declared a function VEC_ADD to add type VECTOR with VECTOR but then tried to add a type POINT with a type POINT (p+p).

IVF 11.1 gives several errors for your mistake.

0 Kudos
Reply