0
$\begingroup$

I was trying to use Fortran function in Mathematica. I was following mainly this answer . My Fortran code looks like this:

FUNCTION TESTFUNCTION(X,Y)

!DEC$ ATTRIBUTES DLLEXPORT::TESTFUNCTION
!DEC$ ATTRIBUTES REFERENCE :: X,Y

REAL(8), DIMENSION(2) :: X
REAL(8) :: Y, TESTFUNCTION
TESTFUNCTION = (X(1)+X(2)) * Y

END FUNCTION

To create .dll I have used Intel Fortran Compiler, while following this guide . My Mathematica input is:

Needs["NETLink`"]
ReinstallNET["Force32Bit" -> True]
SetDirectory[NotebookDirectory[]];
path = FileNameJoin[{Directory[], "testfunction.dll"}];

TestFunction = DefineDLLFunction["TESTFUNCTION_",path ,
"double", {"double[]", "double*"}]

This gives:

(*
Out[26]=Function[Null, 
If[NETLink`DLL`Private`checkArgCount["TESTFUNCTION_", {##1}, 2], 
Wolfram`NETLink`DynamicDLLNamespace`DLLWrapper1`TESTFUNCTIONU[##1], \
$Failed], {HoldAll}]
*)

After calling

TestFunction[{1.0, 2.0}, 3.0]

I've obtained

(*
 Out[27]= NET::netexcptn: 
 A .NET exception occurred: System.EntryPointNotFoundException: 
 Unable to find an entry point named 'TESTFUNCTION_'   
 in DLL 'D:\Files\testfunction\testfunction.dll'.
 at Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper1.TESTFUNCTION_(Double[] ,Double& ).
*)

Can somebody please tell why I have this error message. Any suggestions are more than welcomed. Here is the source code and .dll file.

$\endgroup$
  • $\begingroup$ try without the _ $\endgroup$ – george2079 Apr 29 '16 at 19:57
  • $\begingroup$ @george2079 I've tried that, but with any success (same error message) $\endgroup$ – Moonwalk Apr 30 '16 at 7:07
  • $\begingroup$ Have you solved it? I have encountered the same problem. $\endgroup$ – xin pei Dec 12 '18 at 13:28
  • $\begingroup$ @xinpei try to run it with updated files which I have just uploaded on my dropbox. I think that with these new files it is working. It is been 2 years, so I am not sure :) Let me know if it worked for you. $\endgroup$ – Moonwalk Dec 13 '18 at 15:55
  • $\begingroup$ Thanks @Moonwalk it don't work on my computer. But i found if i use Gfortran this error will not occur. $\endgroup$ – xin pei Dec 14 '18 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.