- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
!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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a clue: if there has been a crime committed, it's probably not the compiler that is responsible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page