专栏
标签
modelica调用refprop
一般问题
发布于 2025-01-09 15:32:26
查看 26过去535天

利用c函数调用refprop,然后modelica调用c语言函数。将refprop.dll,REFPROP2.H,c函数代码,与模型文件均放在同一文件夹,无中文。报错如下

Compiling and linking the model (gcc).

Compiling...

External include directories:

G:/refprop/Model3
F:/SYSPLORER
F:\SYSPLORER\MwSolver_250109_151628
G:/refprop/Model3

In file included from F:\SYSPLORER\MwSolver_250109_151628\momodel_func.c:18:0:
F:\SYSPLORER\MwSolver_250109_151628\momodel_extern_inc.h:17:21: fatal error: 2025_1_9.c: No such file or directory
#include"2025_1_9.c"
^
compilation terminated.

Compiling the model (gcc) failed.

Compiling and linking the model (gcc).

Compiling...

External include directories:

G:/refprop/Model3
F:/SYSPLORER
F:\SYSPLORER\MwSolver_250109_151628
G:/refprop/Model3

In file included from F:\SYSPLORER\MwSolver_250109_151628\momodel_extern_inc.h:17:0,
from F:\SYSPLORER\MwSolver_250109_151628\momodel_func.c:18:
F:\SYSPLORER\MwSolver_250109_151628\2025_1_9.c:3:22: fatal error: refprop2.h: No such file or directory
#include "refprop2.h"
^
compilation terminated.

Compiling the model (gcc) failed.

Compiling and linking the model (gcc).

Compiling...

External include directories:

G:/refprop/Model3
F:/SYSPLORER
F:\SYSPLORER\MwSolver_250109_151628
G:/refprop/Model3

Linking...

External library directories:

G:/refprop/Model3
F:/SYSPLORER
F:\SYSPLORER\MwSolver_250109_151628
G:/refprop/Model3

External libraries:

refprop

F:/mworks/Sysplorer 2024b/Simulator/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.4/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lrefprop
collect2.exe: error: ld returned 1 exit status

Linking the model (gcc) failed.

Compiling and linking the model (gcc).

Compiling...

External include directories:

G:/refprop/Model3
F:/SYSPLORER
F:\SYSPLORER\MwSolver_250109_151628
G:/refprop/Model3

Linking...

External library directories:

G:/refprop/Model3
F:/SYSPLORER
F:\SYSPLORER\MwSolver_250109_151628
G:/refprop/Model3

External libraries:

{refprop

F:/mworks/Sysplorer 2024b/Simulator/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.4/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -l{refprop
collect2.exe: error: ld returned 1 exit status

Linking the model (gcc) failed.

它显示始终找不到文件。这该如何解决呢。

所属专栏:Sysplorer基础平台
产品信息:Sysplorer系统建模仿真环境
系统建模科学计算其他
附件 1 个附件(2873kb)

全部回答 2

发布于 2025-01-09 17:08:49

您好,外部c函数声明时可以按照c的格式,但是在model中调用时,需要按照modelica的格式,即按照function中生命的input输入参数,同时,原来的文件结构需要修改,具体可见图片
image.png
image.png
原函数修改为

function funct
  input Real t;
  input Real p;
  input String herr;
  output Real density;
  output Real enthalpy;
  output Real entropy;
  output Real viscosity;
  output Real thermal_conductivity;
external "C" CalculateProperties(t,p,density,enthalpy,entropy,viscosity,thermal_conductivity,herr) 
 annotation (IncludeDirectory = 
    "modelica://Resources/Include", 
    Include = "#include\"2025_1_9.c\"");
end funct;
model Model2
  Real t = 400;
  Real p = 2e6;
  String c = "a";
  Real d;
  Real f;
  Real d1;
  Real f1;
  Real d2;
equation
  (d,f,d1,f1,d2) = test.funct(t, p, c);
end Model2;

具体调用方式与过程请仔细查看官网课程外部函数

用户
和原帖交流更多问题细节吧,去
我要发帖 我要发帖
资料中心 资料中心
查看更多>
热门帖子 热门帖子
主要贡献者 主要贡献者
过去7天