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

Compile Fortran dll for use in R

Jeff_B_2
Beginner
953 Views

I am totally new to mixed-language programming and am having difficulty creating a dll to be called by R.  I found the following small example which supposedly works for the CVF 6.6 compiler online:

SUBROUTINE MYSUB(X,N,XMEAN)
CDEC$ ATTRIBUTES DLLEXPORT,C,REFERENCE,ALIAS:'mysub_' :: MYSUB
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DOUBLE PRECISION X(N)
XMEAN=0D0
DO 10 J=1,N
XMEAN=XMEAN+X(J)
10 CONTINUE
XMEAN=XMEAN/N
RETURN
END

When I try to load the dll in R using dyn.load(), I receive the following error message (I replaced the long path with <file> in the message):

Error in inDL(x, as.logical(local), as.logical(now), ...) :
  unable to load shared object '<file>':
  LoadLibrary failure:  %1 is not a valid Win32 application.
nd.

I am using XE 12.1 with the Visual Studio shell and R 2.15.1.  Are there other compiler directives or Project settings I shoudl experiment with?

Many thanks!
Jeff
>

0 Kudos
2 Replies
mecej4
Honored Contributor III
953 Views
Please state how you compiled and linked the DLL. Is your installed R 32-bit or 64-bit?
0 Kudos
Jeff_B_2
Beginner
953 Views
I should have thought of that; many thanks! The error message was apparently caused by trying to load a 32 bit dll during a 64 bit R session. Like I mentioned, this is my first experience with a mixed language application.
0 Kudos
Reply