1

I wrote a Fortran code and make it TestDLL.dll and TestDLL.lib file. I want use that in OpenModelica. But the Modelica say that

could not find library TestDLL in either of:~~~

I put .dll and .lib file in E:\MODELICAEXAM (my modelica work space) or E:\MODELICAEXAM\MyPackage\Resouces, but it doesn't work.

I read the ModelicaSpec34 document(12.9.4) which describe about "annotation", but I really confuse about what is "modelica://".

So I have two question about that:

  1. can I use fortran dll in the modelica?
  2. If first question is ok, where should I put my lib and dll file to make modelica find these files? or I misunderstood the question?

The code as below

function SUB(a,b)
!DEC$ ATTRIBUTES DLLEXPORT::SUB
    implicit none
    real :: a,b
    real :: SUB
    SUB = a+b
return
end

modelica part

model test
    function sub
       input Real a;
       input Real b;
       output Real Result;
       external "C" Result = sub(a, b);
       annotation(
       Library = "TestDLL",
       LibraryDirectory = 
           "modelica://MyPackage/Resouces");
    end sub;

    Real result;
    parameter Real a = 1;
    parameter Real b = 2;
equation
    result = sub(a, b);
end test;!
yx171532
  • 11
  • 2
  • What does the spec says about annotation? What you tried is not Fortran, it can't compile. How did you make the dll? Did you get any error message? – Vladimir F Героям слава Nov 24 '19 at 08:46
  • the spec says that the annotation(LibraryDirectory="modelica://LibraryName/Resources/Library"), but I don't know what does the "modelica://"represent. The Fortran code that I have compiled in IVF 2013 have already been tried in another Fortran code and works well. – yx171532 Nov 24 '19 at 09:51
  • this is the modelicaspec34 document https://www.modelica.org/documents/ModelicaSpec34.pdf – yx171532 Nov 24 '19 at 09:52
  • 1
    OpenModelica uses GCC so you need to compile your code to a libTestDLL.a or .dll using gfortran. Extension .lib does not work. – Adrian Pop Nov 24 '19 at 10:58
  • Can't you quote from the document yourself so that all other people don't have to? You are asking for help, after all. – Vladimir F Героям слава Nov 24 '19 at 12:46
  • The `LibraryDirectory` specification looks nothing like what would work on Windows. Maybe this is converted by OpenModelica into something else. I will comment, though, that the error "could not find library DLL" often means that a DLL that your DLL depends on could not be found. This happens most often when you build a debug-configuration DLL that depends on C++ (and possibly Fortran) support DLLs that are available only when inside Visual Studio or a compiler build environment. Which compiler are you using and how did you build the DLL? – Steve Lionel Nov 25 '19 at 00:37

1 Answers1

0

Thanks for your answers. I have solved this question. Fortran make the variable to capital form automatically. When I use this function in modelica, I must use capital form to call the function. The "modelica://" means the file folder where the. mo file located.

yx171532
  • 11
  • 2