I followed and adapted your links :
with the following codes :
The dll code :
function mysum(x,y) result(z) !DEC$ ATTRIBUTES DLLEXPORT :: mysum INTEGER x, y z = x+y end function mysum function myprod(x,y) result(z) !DEC$ ATTRIBUTES DLLEXPORT :: myprod INTEGER x, y z = x*y end function myprod
in dll.F90 and the client code :
program CallingTheDLL !DEC$ ATTRIBUTES DLLIMPORT:: mysum !DEC$ ATTRIBUTES DLLIMPORT:: myprod integer i, j integer resS integer resP print*,"enter two integers" read (*,*) i,j resS = mysum(i, j) resP = myprod(i, j) print*,"Sum of ",i," and ",j," is = ",resS print*,"Product of ",i," and ",j," is = ",resP read(*,*) end program CallingTheDLL
The structure in the folder is :
I have a folder DLL_EXAMPLE containin two folders :
- DLL that contains dll.F90
- CLIENT that contains client.F90
In the folder DLL I run :
ifort /align:commons /dll dll.F90
which gives to me the output :
-out:dll.dll -dll -implib:dll.lib dll.obj Creating library dll.lib and object dll.exp
then in the CLIENT I run :
ifort /align:commons /dll client.exe .\..\DLL\dll.obj /link .\..\DLL\dll.dll
which gives to me the outup :
-out:client.dll -dll -implib:client.lib .\..\DLL\dll.dll client.exe .\..\DLL\dll.obj .\..\DLL\dll.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2F0
Remark : if I run
ifort -o client.exe /dll .\..\DLL\dll.obj /link .\..\DLL\dll.lib
instead I don't have an error, and have this output :
-out:client.exe -dll -implib:client.lib .\..\DLL\dll.lib .\..\DLL\dll.obj Creating library client.lib and object client.exp
but when I double click the exe I have a windows 10 pop up "This app can't run on your PC" and if I try to run it from the command line, I have :
C:\WORK\CODING\MY\SHIT\FORTRAN\TOYING\DLL_EXAMPLE>.\CLIENT\client.exe Access is denied.
Adding `/align:commons` or not doesn't change anything.
What did I do wrong and how to correct ?
Ok, this command did the job :
ifort client.F90 ..\DLL\dll.lib
And I need to have `dll.dll` and `dll.lib` in the same folder (CLIENT) as `client.exe` for the latter to run properly.