External Functions: Reference headers in C-script to compiled dll

无人久伴 提交于 2019-12-01 20:20:50

I believe this can only be resolved with relative include paths or future tools that implement future Modelica Language Specification 3.4. See https://trac.modelica.org/Modelica/ticket/2103 for the corresponding update on the Modelica Language Specification.

You set include directory to modelica://ExternalFuncTest/Resources/Source/gsl-1.8/ and then use #include <gsl-1.8/gsl/gsl_errno.h>

Do you really have a directory gsl-1.8 in the directory gsl-1.8 (some projects have such a structure - but it is generally rare)? If that is not the case change to #include <gsl/gsl_errno.h>.

I believe hierarchical includes are also searched in the path and thus that should work; otherwise you could always set includeDirectory to modelica://ExternalFuncTest/Resources/Source/gsl-1.8/gsl and use #include <gsl_errno.h>.

Scott G

Referencing compiled library headers from c-scripts that are called by a Modelica external function call is possible.

However, it is still not determined if there is an efficient method to access the .dll. This is discussed in a follow up question External Functions: Alternative Method to use .dll from a C-script.

The solution that allowed the header files to be recognized is presented. Thanks to all who responded in helping figure this out.


Step 1) Create Folder Structure

Modelica looks in default directories automatically for external function dependencies. Section 12.9.4 of modelica.org/documents/ModelicaSpec33Revision1.pdf

The default location that Modelica looks for compiled libraries is a folder called Library within the Resources folder of your project:

LibraryDirectory="modelica://LibraryPackageName/Resources/Library"

For header files and c-scripts the default location is a folder called Include within the Resources folder of your project:

IncludeDirectory="modelica://LibraryPackageName/Resources/Include"

To specify alternative directories follow the modelica spec document. As of Modelica Specification 3.3 Rev 1 you can only specify one LibraryDirectory and one IncludeDirectory. Though this may be addressed in the future https://trac.modelica.org/Modelica/ticket/2103.

Summary of Overall Folder Structure

Step 2) Create Modelica Function and C-Scripts in locations specified in above image

Below are examples that can be used for reference.

Modelica Function

function chirp

  input Modelica.SIunits.AngularVelocity w_start;
  input Modelica.SIunits.AngularVelocity w_end;
  input Real A;
  input Real M;
  input Real t;
  output Real u "output signal";

  external "C" u=chirp(w_start,w_end,A,M,t)
    annotation(Library="libgsl",Include="#include \"chirp.c\"");

end chirp;

C-Script

#include <gsl/gsl_sf_bessel.h>

double chirp(double w1, double w2, double A, double M, double time)
{
  double res;
  res=A*cos(w1*time+(w2-w1)*time*time/(2*M));
  return res;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!