Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

How to call an dynamic link library?

zlzgj
Beginner
796 Views

I wrote an dynamic link library below, and it is successfully builtto an dll.
butI don't know how ro call it.
!!!!!!!!!!!!!!!!the dll below !!!!!!!!!!!!!!!!!!!!!!!!!!
module MM
!DEC$ OBJCOMMENT LIB:'libiomp5md.lib'
include 'link_fnl_static_hpc.h'
USE numerical_libraries
real:: A(2),B(2), INV(2,2)
END MODULE MM
!
!
MODULE FF
INTERFACE
subroutine Dis
Use MM
end subroutine Dis
END INTERFACE
END MODULE FF
!
!
subroutine MainSub(AA,BB)
!DEC$Attributes Stdcall , Dllexport , Alias : 'MainSub' :: MainSub
!DEC$Attributes Reference :: AA,BB
Use MM
use FF
real:: AA(2),BB(2)
A=AA
B=BB
call Dis
end subroutine MainSub
!
!
subroutine Dis
Use MM
implicit none
real :: C
INV=reshape((/1.0,0.0,0.0,2.0/),(/2,2/))
C=BLINF(2, 2, INV, 2,A, B)
print*,C
end subroutine Dis
!

!!!!!!!!!!!!!!!!!!!!!!!! the program mainpto call the dll below !!!!!!!!!!!!!!!!!!!!!!!!!!!
program Mainp
INCLUDE 'link_fnl_shared.h'
!DEC$ OBJCOMMENT lib:"libiomp5md.lib"
implicit none
Interface
Subroutine MainSub(A,B)
Real :: A(2),B(2)
End Subroutine
End Interface
real:: AA(2),BB(2)
AA=(/1.0,1.0/)
BB=(/2.0,0.0/)
call MainSub(AA,BB)
end program Mainp
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


My compiler is : IVF 11.1.051,IMSL6.0, win7, IA32, VS2008 .

thanks !

zlzgj

0 Kudos
2 Replies
Steven_L_Intel1
Employee
796 Views
Two comments. First, you have a mix of library types with one source including 'link_fnl_static.h" and the other "link_fnl_shared.h". This is bad. Pick one or the other. If you pick the shared, remove the OBJCOMMENT lines.

Second, you have not added a !DEC$ ATTRIBUTES DLLEXPORT directive for any of your routines. Without that, there is no export library created and you can't call any routines. In each routine you want callable, add:

!DEC$ ATTRIBUTES DLLEXPORT :: routinename

Then when you link the DLL, a .lib will be created. Build the calling program with this library.
0 Kudos
zlzgj
Beginner
796 Views
Hellow, Steve:

thanks for your help. according to what you said, I tried it again and I did it.

thanks you very much!

zlzgj
0 Kudos
Reply