Hi,
Back again, sorry for reacting that late, I was on a trip, I used @mikrom and @xwb to answer.
@mikrom:
Thanks! Works great!
As well as the dll as the executable build and compile perfectly.
I tried to separate compiling and building (a matter of taste to see what I'm doing) and used a batch file like:
Code:
REM DLL compile
gfortran -c sub_twice.f90
REM DLL build
gfortran -shared -mrtd -o sub_twice.dll sub_twice.o
REM EXE compile
gfortran -c main.f90
REM EXE build
gfortran main.o -o main.exe -L. sub_twice.dll
With the simple code for the dll
Code:
SUBROUTINE Twice(x,y)
IMPLICIT NONE
REAL, INTENT(IN) :: x
REAL, INTENT(OUT) :: y
y=2*x
END SUBROUTINE Twice
And for the executable
Code:
SUBROUTINE Twice(x,y)
IMPLICIT NONE
REAL, INTENT(IN) :: x
REAL, INTENT(OUT) :: y
y=2*x
END SUBROUTINE Twice
What amazes me a bit is that we don't need to use something in the dll like:
Code:
!DEC$ ATTRIBUTES DLLEXPORT::Twice
And in the exe something like:
Code:
!DEC$ ATTRIBUTES DLLIMPORT::Twice
...or !GCC$
It seems to work fine without these compiler commands that seem to be called "compiler directives"... ???
I suppose that the necessity to use these commands is compiler dependent
Thanks for the tip about
Dependency Walker, I'll use it to check commercial dll's. Checking my own dll gives:
"twice_" as the function name indeed on the export window. You can't see which variables are going in or out, can you?
When I load the executable, it doesn't show "twice_" on the PI import window however, I suppose that
Dependency Walker only works with DLL's, right?
Something that doesn't have to do anything with building DLL's but that I saw in your example and was new to me, is that you seem to use your function f1 as an argument to your function simpson ??
Is it therefore necessary to use the "INTERFACE" statement in the function "simpson"?? (Never knew what these interfaces were for anyway...) Amazing, I didnt know it existed!
@xwb:
Thanks for looking up your fortran power station compiler!!
The first thing I noticed is that you either used "compiler directives" like !DEC$ etc., are these not necessary?
About the def file, it's not clear to me whether the name of the library, in your case "testlib" should be the same as the name of your DLL, or the function in your DLL.
Using only 2 variables, I get indeed a message that _TWICE@8 is missing, which meets perfectly the name convention you mentioned.
So, I made a file "twice.def" that contains:
Code:
LIBRARY sub_twice
EXPORTS
_TWICE@8
Adding that to my project options in the DLL workspace it looks like
Code:
/Ox /I "Release/" /c /nologo /MT /Fo"Release/ /def:twice.def "
But the lib file is not generated....???
Adding "/export:_TWICE@8" does not work either, I tried in the DLL workspace and in the EXE workspace before building, again I get the message that _TWICE@8 is missing...
After all, it seems very complicated and laborious in Developer Studio
P.S.: About the old power station, you mention the spaces in the directory name. Be careful using directory names longer than 8 characters with this compiler, the debug function only works for directory names upto 8 characters!!
Regards,
Gerrit